Spline을 따라 고정된 속도(cm/s)로 이동하기

MoOrY·2023년 4월 20일
0

언리얼 엔진

목록 보기
24/41
void AMoveSplineAtFixedSpeed::MoveThroughSpline(float DeltaSeconds)
{
	//전체 SPline길이인 SplineLength는 SplineLength = SplineComponent->GetSplineLength();로 구한다.
    //MoveSplineSpeed는 움직일 속도이다. 단위는 cm/s이다.
	CurrentSplineMoveLength 
    	= FMath::Min(SplineLength, CurrentSplineMoveLength + MoveSplineSpeed * DeltaSeconds * ReverseValue);

	const FVector CurrentSplineLocation 
    	= SplineComponent->GetLocationAtDistanceAlongSpline(CurrentSplineMoveLength, ESplineCoordinateSpace::World);
	const FRotator CurrentSplineRotation 
    	= SplineComponent->GetRotationAtDistanceAlongSpline(CurrentSplineMoveLength, ESplineCoordinateSpace::World);
	 
	const FVector NewLocation = CurrentSplineLocation + LocationOffset;
	const FRotator NewRotation = CurrentSplineRotation + RotateOffset;
	
	MeshComponent->SetWorldLocation(NewLocation);

	if(bRotateWithSpline == true)
	{
		MeshComponent->SetWorldRotation(NewRotation);
	}
	
	if(CurrentSplineMoveLength >= SplineLength)
	{
		MeshComponent->SetWorldLocation(LastSplinePointLocation);
		MeshComponent->SetWorldRotation(LastSplinePointRotator);
		bActivate = false;

		if(EndActionDelayTime <= 0)
		{
			SplineEndAction();
		}
		else
		{
			GetWorldTimerManager().SetTimer(ResetTimerHandle, this, &AMoveSplineAtFixedSpeed::SplineEndAction, EndActionDelayTime, false);	
		}
	}
}
profile
필기용 블로그입니다.

0개의 댓글