Transform 관련 함수

김민수·2025년 1월 22일

언리얼 C++

목록 보기
13/32

1. 위치 변경 및 가져오기

⦁ SetActorLocation(FVector NewLocation)

액터의 위치를 지정된 FVector 값으로 변경한다.

FVector NewLocation = FVector(100.f, 200.f, 300.f);
MyActor->SetActorLocation(NewLocation);
  • 위치 변경이 실패하면 false를 반환할 수도 있다.
  • Sweep(충돌 감지) 옵션을 활성화하면 충돌을 고려한 이동이 가능하다.

⦁ GetActorLocation()

현재 액터의 위치를 FVector 형태로 반환한다.

FVector CurrentLocation = MyActor->GetActorLocation();
  • 반환된 값은 월드 좌표 기준의 위치다.


2. 회전 변경 및 가져오기

⦁ SetActorRotation(FRotator NewRotation)

액터의 회전을 지정된 FRotator 값으로 변경한다.

FRotator NewRotation = FRotator(0.f, 90.f, 0.f); // Pitch, Yaw, Roll
MyActor->SetActorRotation(NewRotation);
  • 회전은 Yaw(수평), Pitch(수직), Roll(좌우 기울기) 값을 사용하여 설정한다.

⦁ GetActorRotation()

현재 액터의 회전을 FRotator 형태로 반환한다.

FRotator CurrentRotation = MyActor->GetActorRotation();
  • 회전 값도 월드 좌표 기준으로 반환된다.


3. 스케일 변경 및 가져오기

⦁ SetActorScale3D(FVector NewScale)

액터의 스케일을 지정된 FVector 값으로 변경한다.

FVector NewScale = FVector(2.f, 2.f, 2.f); // X, Y, Z 방향으로 두 배
MyActor->SetActorScale3D(NewScale);
  • 스케일 값은 각 축(X, Y, Z)에 대해 독립적으로 설정된다.

⦁ GetActorScale3D()

  • 현재 액터의 스케일을 FVector 형태로 반환한다.
FVector CurrentScale = MyActor->GetActorScale3D();
  • 반환된 스케일 값도 월드 좌표 기준이다.


4. Transform 전체를 한 번에 설정하기

⦁ SetActorTransform(FTransform NewTransform)

위치, 회전, 스케일을 포함한 전체 Transform을 한 번에 설정한다.

FVector NewLocation = FVector(100.f, 200.f, 300.f);
FRotator NewRotation = FRotator(0.f, 90.f, 0.f);
FVector NewScale = FVector(2.f, 2.f, 2.f);

FTransform NewTransform(NewRotation, NewLocation, NewScale);
MyActor->SetActorTransform(NewTransform);
  • FTransform은 위치, 회전, 스케일 값을 모두 포함하는 구조체다.

⦁ GetActorTransform()

현재 액터의 Transform(위치, 회전, 스케일)을 FTransform 형태로 반환한다.

FTransform CurrentTransform = MyActor->GetActorTransform();


5. Transform 관련 추가 함수들

⦁ AddActorWorldOffset(FVector DeltaLocation)

현재 위치에서 지정된 벡터 값만큼 이동한다.

FVector DeltaLocation = FVector(50.f, 0.f, 0.f); // X 방향으로 50만큼 이동
MyActor->AddActorWorldOffset(DeltaLocation);

⦁ AddActorWorldRotation(FRotator DeltaRotation)

현재 회전에 지정된 FRotator 값만큼 추가로 회전한다.

FRotator DeltaRotation = FRotator(0.f, 45.f, 0.f); // Yaw 값 45도 증가
MyActor->AddActorWorldRotation(DeltaRotation);

⦁ SetActorRelativeLocation, SetActorRelativeRotation, SetActorRelativeScale3D

부모 액터를 기준으로 상대적인 Transform을 설정한다. 월드 기준이 아니라 부모의 Transform에 따라 설정된다.

FVector RelativeLocation = FVector(50.f, 0.f, 0.f);
MyActor->SetActorRelativeLocation(RelativeLocation);

FRotator RelativeRotation = FRotator(0.f, 30.f, 0.f);
MyActor->SetActorRelativeRotation(RelativeRotation);

FVector RelativeScale = FVector(1.5f, 1.5f, 1.5f);
MyActor->SetActorRelativeScale3D(RelativeScale);
profile
안녕하세요

0개의 댓글