Turret behaving strangely

Hi.

When I aim past the midline of the tank, to the right, the turret rotates 180 degrees on the opposite direction. I’ve tried debugging the line-tracing to check if it was colliding with my own tank, as seen on another thread, but it was fine. I’ve also tried the corrected rotation code seen further in the lectures:

void UTankAimingComponent::MoveBarrelTowards(FVector AimDirection)
{
	if (!ensure(Barrel && Turret)) { return; }

	auto BarrelRotator = Barrel->GetForwardVector().Rotation();
	auto AimAsRotator = AimDirection.Rotation();
	auto DeltaRotator = AimAsRotator - BarrelRotator;

	Barrel->Elevate(DeltaRotator.Pitch);

	if (FMath::Abs(DeltaRotator.Yaw) < 180)
	{
		Turret->Rotate(DeltaRotator.Yaw);
	}
	else
	{
		Turret->Rotate(-DeltaRotator.Yaw);
	}
}

Didn’t work either. I’m totally lost.
I’m using Unreal 4.23 (don’t know if this could be causing the problem?).
My github repo can be found here: https://github.com/FreitasRod/BattleTank

Video of the glitch (I’ve added debug lines in SuggestProjectileVelocity function):

Thanks to anyone who can help me with this. :slight_smile:

I found a “solution”. Instead of using the normalized value of OutLaunchVelocity, I just used its value as is to call the MoveBarrelTowards() function. I don’t know if there’s a bug with .GetSafeNormal(), but normalizing doesn’t work for me on Unreal 4.23.
Cheers.

It’s a problem with MSVC 16.3. They introduced a bug, planned fix for 16.4 (will be in the next preview release).

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms