본문 바로가기
Unreal Engine5/게임 만들기 - Obstacle Assault

Unreal Engine 움직임 버그 fix

by wanna_dev 2023. 7. 7.

원래 좌우로 움직이던, 코드에 버그가 있어서 수정했다.

버그 내용은 다음과 같았다. 

분기문의 DistanceMoved 와 MoveDistance를 비교하기 때문에 빠른 속도로 큰 거리를 이동하면, 내가 생각한 범위보다 더 움직이는 문제가 발생했던 것이었다. 

 

수정된 내용은 다음과 같다.

void AMovingFlatform::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	FVector CurrentLocation = GetActorLocation();

	CurrentLocation = CurrentLocation+(PlatformVelocity * DeltaTime);
	SetActorLocation(CurrentLocation);
	float DistanceMoved = FVector::Dist(StartLocation, CurrentLocation);

	if(DistanceMoved > MoveDistance)
	{
		FVector MoveDirection = PlatformVelocity.GetSafeNormal();
		StartLocation = StartLocation + MoveDirection * MoveDistance;
		SetActorLocation(StartLocation);
        PlatformVelocity = -PlatformVelocity;
	}

}

 

움직임을 계산할때는 항상 정확한 이동량을 기반으로 움직여야한다는 것이다.