오늘은 저번에 Character 클래스로 간단하게 구현했던 부분들을 Pawn 클래스에서 구현해보려고 한다.
언리얼에서 기본적으로 제공해주는 내장기능을 이용하지 않고 직접 구현하는 방식으로...

전체적인 로직의 흐름이나 라이프 사이클은 저번에 구현했던 Character 클래스와 유사하게 가지만,
나의 개발길을 편하게 해주는.. 천사같은 언리얼 내장 함수는 .. 이번엔.. 과감..하게 버린채로 순수 구현을 해보려고한다..
void AMyCharacter::Move(const FInputActionValue& value)
{
FVector2D MoveInput = value.Get<FVector2D>();
FVector Forward = GetActorForwardVector();
FVector Right = GetActorRightVector();
FVector MoveDirection = (Forward * MoveInput.Y) + (Right * MoveInput.X);
MoveDirection.Z = 0.0f;
const float DeltaTime = GetWorld()->GetDeltaSeconds();
FVector DeltaLocation = MoveDirection * MoveSpeed * DeltaTime;
AddActorLocalOffset(DeltaLocation, true);
}
Move에서는 앞 뒤 이동을 GetActorForwardVector로 가져와줬고, 좌우도 RightVector를 가져와서 처리해주었다.
그리고 Tick 함수는 프레임마다 돌아서 부담이 많이 된다고 하길래 Move 함수 안에서 DeltaTime을 가져와 구현해보았다.
void AMyCharacter::Look(const FInputActionValue& value)
{
FVector2D LookInput = value.Get<FVector2D>();
float YawDelta = LookInput.X * YawSensitivity;
AddActorLocalRotation(FRotator(0.0f, YawDelta, 0.0f));
FRotator CurrentRotation = SpringArmComponent->GetRelativeRotation();
float NewPitch = FMath::Clamp(CurrentRotation.Pitch + LookInput.Y * PitchSensitivity, MinPitch, MaxPitch);
SpringArmComponent->SetRelativeRotation(FRotator(NewPitch, CurrentRotation.Yaw, CurrentRotation.Roll));
}
그리고 카메라 회전부분인데.. 여기서 좀 많이 어려워서.. 채찍피티의 도움을 살짝(아주많이.).. 받았다

짜잔.. 캐릭터 내가 원한건 카메라의 시점이 회전하는 걸 원했는데 캐릭터 자체가 회전해버린다.
뭐가 문제인지 내일 찬찬히 뜯어봐야겠다.
아.. 그리고 슬프게도 점프는 중력을 구현하려다 실패해서 이 아이는 아직 점프를 배우지 못한.. 슬픈..아이이다..
'Unreal Engine' 카테고리의 다른 글
[ UE, C++ ] 아이템 만들기 (0) | 2025.02.07 |
---|---|
[ UE ] StateMachine을 활용해 캐릭터에 생기 불어넣기 (0) | 2025.02.06 |
[ UE ] 개발하면서 알아두면 좋은 내용들 (0) | 2025.02.04 |
[ UE ] Texture Coordinates 노드 활용 - 타일링 (0) | 2025.01.31 |
[ UE, C++ ] Actor를 다양하게 회전시켜보자 (0) | 2025.01.27 |