58 lines
1.7 KiB
C++
Executable File
58 lines
1.7 KiB
C++
Executable File
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "BasePawn.h"
|
|
#include "Components/StaticMeshComponent.h"
|
|
#include "GameFramework/FloatingPawnMovement.h"
|
|
|
|
// Sets default values
|
|
ABasePawn::ABasePawn(const FObjectInitializer &object_initializer):
|
|
APawn(object_initializer)
|
|
{
|
|
// Create default components.
|
|
root_component = object_initializer.CreateDefaultSubobject<USceneComponent>(this, FName("Root"));
|
|
player_mesh = object_initializer.CreateDefaultSubobject<UStaticMeshComponent>(this, FName("PlayerMesh"));
|
|
movement_component = object_initializer.CreateDefaultSubobject<UFloatingPawnMovement>(this, FName("MovementComponent"));
|
|
|
|
// Setup component hierarchy.
|
|
RootComponent = root_component;
|
|
player_mesh->SetupAttachment(root_component);
|
|
movement_component->UpdatedComponent = player_mesh;
|
|
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
}
|
|
|
|
// Called when the game starts or when spawned
|
|
void ABasePawn::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
}
|
|
|
|
UPawnMovementComponent* ABasePawn::GetMovementComponent() const
|
|
{
|
|
return movement_component;
|
|
}
|
|
|
|
// Called every frame
|
|
void ABasePawn::Tick(float DeltaTime)
|
|
{
|
|
Super::Tick(DeltaTime);
|
|
}
|
|
|
|
void ABasePawn::handle_move_forward(float axis)
|
|
{
|
|
FRotator rotation = Controller->GetControlRotation();
|
|
FRotator yaw(0.0f, rotation.Yaw, 0.0f);
|
|
|
|
FVector forward = FRotationMatrix(yaw).GetUnitAxis(EAxis::X);
|
|
AddMovementInput(forward, axis);
|
|
}
|
|
|
|
void ABasePawn::handle_move_right(float axis)
|
|
{
|
|
FRotator rotation = Controller->GetControlRotation();
|
|
FRotator yaw(0.0f, rotation.Yaw, 0.0f);
|
|
|
|
FVector right = FRotationMatrix(yaw).GetUnitAxis(EAxis::Y);
|
|
AddMovementInput(right, axis);
|
|
} |