Mesh 지정
애니메이션 지정
키보드 매핑
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Main.generated.h"
UCLASS()
class BASIC_API AMain : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMain();
/** Camera boom positioning the camera begind the player */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
/** Follow Camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* FollowCamera;
/** Base turn rates to scale turning functions for the Camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
float BaseTurnRate;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
float BaseLookUpRate;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
/** Called for forward/backword input */
void MoveForward(float value);
void MoveRight(float value);
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "Main.h"
#include <Engine/Classes/GameFramework/SpringArmComponent.h>
#include <Engine/Classes/Camera/CameraComponent.h>
// Sets default values
AMain::AMain()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Create Camera Boom (pulls towards the player if there's a collision
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(GetRootComponent());
// Camera follows at this distance
CameraBoom->TargetArmLength = 600.f;
// Rotate arm based on controller
CameraBoom->bUsePawnControlRotation = true;
// Create Foloow Camera
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
// Attach the camera to the end of the boom and let the boom adjust to match
// the controller origintation
FollowCamera->bUsePawnControlRotation = false;
// Set our turn rates for input
BaseTurnRate = 65.f;
BaseLookUpRate = 65.f;
}
// Called when the game starts or when spawned
void AMain::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMain::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AMain::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
void AMain::MoveForward(float value)
{
if (Controller != nullptr && value != 0.0f)
{
// find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0.f, Rotation.Yaw, 0.f);
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, value);
}
}
void AMain::MoveRight(float value)
{
if (Controller != nullptr && value != 0.0f)
{
// find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0.f, Rotation.Yaw, 0.f);
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
AddMovementInput(Direction, value);
}
}