컴포넌트에서 액터의 위치를 구하고자 할때
GetOwner()->GetActorLocation();
길이 차이을 알고싶을때
Dist(A, B);
벡터의 방향을 유지하면서 길이를 1로 만드는 단위 벡터를 계산
A.GetSafeNormal();
코드
void UMover::Move(float DeltaTime) { if (ShouldPlatformReturn()) { //돌아가야 할때 FVector MoveDirection = MoveVelocity.GetSafeNormal(); //움직일 방향 StartLocation = StartLocation + MoveDirection * MoveDistance; //움직이는 코드 GetOwner()->SetActorLocation(StartLocation); //실시간 액터 위치 지정 MoveVelocity = -MoveVelocity; //방향 전환 } else { FVector CurrentLocation = GetOwner()->GetActorLocation(); //실시간 위치 확인 CurrentLocation = CurrentLocation + (MoveVelocity * DeltaTime); //움직이는 코드 GetOwner()->SetActorLocation(CurrentLocation); //실시간 액터 위치 지정 } } bool UMover::ShouldPlatformReturn() { return GetDistanceMoved() > MoveDistance; // 거리차이가 움직여야할 거리가 멀어져있는가? } float UMover::GetDistanceMoved() { return FVector::Dist(StartLocation, GetOwner()->GetActorLocation()); //시작지점과 현재 위치간의 거리차이 }