Turret Rotation Improvements

I edited UTankTurret::Rotate function and turret can rotate 360 degrees without any problem. It is works for me. Hope its helps to you guys. Have a nice day.

void UTankTurret::Rotate(float RelativeSpeed) 
{
	RelativeSpeed = FMath::Clamp<float>(RelativeSpeed, -1, 1);
	auto RotationChange = RelativeSpeed * MaxDegreesPerSecond * GetWorld()->DeltaTimeSeconds;
	float Rotation = 0.f;
	if (RelativeRotation.Yaw < -70.f || RelativeRotation.Yaw > 70.f)
	{
		Rotation = RelativeRotation.Yaw + FMath::Abs<float>(RotationChange) * -1.f;
	}
	else 
	{
		Rotation = RelativeRotation.Yaw + RotationChange;
	}

	SetRelativeRotation(FRotator(0, Rotation, 0));


}

Update: When you keep move to left its ok but otherwise its not working. Im waiting for your answers.

This is addressed in later lectures :slight_smile:

Privacy & Terms