Turret Turning the long way around

I’m at “Starting With Green” lecture. Just got the tank aiming again and noticed that if I target to the left, the turret moves clockwise around the back of the tank to find it’s target instead of just moving a few inches counterclockwise. Can anyone tell me why and how to make it just move the few inches instead of going all the way around.

Use FMath::Abs() or DeltaRotator.GetNormalized() In your rotate towards function. Ben uses FMath::Abs In a later lecture.

if (FMath::Abs(DeltaRotator.Yaw) < 180) //or if (DeltaRotator.GetNormalized().Yaw < 180)
{
	Turret->Rotate(DeltaRotator.Yaw);
}
else // Avoid going the long-way round
{
	Turret->Rotate(-DeltaRotator.Yaw);
}
1 Like