Download

Character Rotation

Hello,

i’m trying to smoothly rotate my patrol, i have already tried InterpSpeed 0.1, 0.0001, 5, 6, 12… but seems i can’t solve the issue. The code i’m using to smoothly rotates my patrol it’s within the method Tick() as you can see in the code.

What am I doing wrong? Thank you.



void APatrolController::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	if (Patrol)
	{
			uint8 Evaluate = this->ActualState();
			FRotator Obtained;

			if (Evaluate == PatrollingState)
			{
				FVector pVector = Patrol->GetPathIndex(ActualRoute);

				Obtained = GetPatrolRotator(Patrol->GetPathIndex(ActualRoute));
			}
			else if (Evaluate == PursueState)
			{
				if (Player)
				{
					Obtained = GetPatrolRotator(Player->GetActorLocation());
				}
				else
				{
					this->FindPlayer();
				}
			}
			else if (Evaluate == ReturningState)
			{
				Obtained = GetPatrolRotator(LastPosition);
			}

			FRotator newRotator = FMath::RInterpConstantTo(Patrol->GetActorRotation(), Obtained, DeltaSeconds, 12.0f);

			Patrol->SetActorRotation(newRotator);
		
	}
}

FRotator APatrolController::GetPatrolRotator(FVector pVector)
{
	if (Patrol)
	{
		FRotator ReceivedRotator = FRotationMatrix::MakeFromX(pVector - Patrol->GetActorLocation()).Rotator();

		FRotator ToSend(0, ReceivedRotator.Yaw, 0);

		return ToSend;
	}

	return FRotator(0, 0, 0);
}