- Pawn과 Character 차이
- Character는 기본적으로 Capsule, SkeletalMesh, CharacterMovementComponent가 포함되어 있음.
- Pawn은 기본 이동 로직이 없으므로 직접 이동 로직을 구현해야 함.
- 이동 구현 구조
- Move 함수는 FInputActionValue를 받아서 Controller Rotation 기준으로 이동 방향 계산
- Tick에 의존하지 않고 AddActorWorldOffset을 사용해 바로 이동 가능
- DeltaTime을 곱하면 프레임 독립적 이동 가능
- Move 함수 작성 예시
void AMyCharacter::Move(const FInputActionValue& Value)
{
if (!Controller) return; const FVector2D Input = Value.Get<FVector2D>();
if(Input.IsNearlyZero()) return;
const float DeltaTime = GetWorld()->GetDeltaSeconds();
const float Speed = NormalSpeed; // Controller Rotation에서 Yaw만 사용
const FRotator ControlRot = Controller->GetControlRotation();
const FRotator YawRot(0.0f, ControlRot.Yaw, 0.0f); // Forward / Right 방향 계산
const FVector Forward = FRotationMatrix(YawRot).GetUnitAxis(EAxis::X);
const FVector Right = FRotationMatrix(YawRot).GetUnitAxis(EAxis::Y); // 입력값으로 이동 벡터 생성
const FVector MoveDir = Forward * Input.X + Right * Input.Y; // 이동 적용 AddActorWorldOffset(MoveDir.GetSafeNormal() * Speed * DeltaTime, true);
}
4. InputAction 바인딩
- EnhancedInputComponent에서 Action 바인딩 후 Move 함수 호출
- Tick 없이도 실시간 이동 가능
'내배캠 TIL' 카테고리의 다른 글
| [내배캠 TIL 260123] Unreal Engine Collision 정리 (0) | 2026.01.23 |
|---|---|
| [내배캠 TIL 260121] UnrealEngine 블루프린트와 C++ 우선순위, 맵 저장 오류, 카메라 회전 직접 구현 (0) | 2026.01.21 |
| [내배캠 TIL 260116] Unreal PlayerController 와 Input Mapping Context (0) | 2026.01.16 |
| [내배캠 TIL 260112] Unreal Timer를 활용한 액터 생성 (0) | 2026.01.13 |
| [내배캠 TIL 260112] Unreal c++을 활용한 액터의 이동과 회전 (0) | 2026.01.12 |