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.