FVector && FRotator

Ryan Ham·2024년 6월 19일
1

Unreal Engine

목록 보기
10/27

Unreal의 좌표 시스템

Unreal에서는 X축을 Roll, Y축을 Pitch, Z축을 Yaw라고 한다. 우리가 일반적으로 아는 XYZ 좌표축에서 XY의 위치를 서로 바꾼 형태를 Unreal에서는 사용하고 있다.

FVector

Fvector의 X,Y,Z의 순서는 X-Y-Z로 동일하다. (Roll, Pitch, Yaw 순)

FRotator

FRotator의 X,Y,Z의 순서는 Y-Z-X의 순서이다. (Pitch, Yaw, Roll 순)


다음은 FVector와 FRotator를 사용해서 Actor의 위치와 방향을 바꾸는 코드이다. AMyActor의 생성자에서 위치와 방향의 초기값을 setting 해주고, MoveAndRotateActor 함수에서 각각AddActorWorldOffsetAddActorWorldRotation을 통해 위치와 회전을 기존값에 더할 수 있다.

#include "MyActor.h"

// Sets default values
AMyActor::AMyActor()
{
    // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

    // Initialize position and rotation
    InitialPosition = FVector(0.0f, 0.0f, 0.0f);
    InitialRotation = FRotator(0.0f, 0.0f, 0.0f);
}

void AMyActor::MoveAndRotateActor()
{
    // Define movement and rotation
    FVector Movement = FVector(100.0f, 0.0f, 0.0f); // Move 100 units forward along the X-axis
    FRotator Rotation = FRotator(0.0f, 45.0f, 0.0f); // Rotate 45 degrees around the Yaw (Z-axis)

    // Apply movement and rotation
    AddActorWorldOffset(Movement);
    AddActorWorldRotation(Rotation);
}
profile
🏦KAIST EE | 🏦SNU AI(빅데이터 핀테크 전문가 과정) | 📙CryptoHipsters 저자

0개의 댓글