My Turret is rotating in wrong direction

I got weird problem with my turret. Its sometime rotating in wrong direction

What can be wrong with my code?

void UTankAimingComponent::MoveBarrelTowards(FVector AimingDirection)
auto BarrelRotator = Barrel->GetForwardVector().Rotation();
auto AimAsRotator = AimingDirection.Rotation();
auto DeltaRotator = AimAsRotator - BarrelRotator;




This was an interesting point brought up in the section-production-progress thread (not sure how to link to it!) so I think this will be addressed in a future video if it hasn’t been already.

It is indeed addressed in a few lectures time

I got the same issue, I know what is wrong, but not sure how to fix it :slight_smile:

Have you tried a negative sign in front of the yaw?

Hey Ben,

Thanks for responding. That’s not quite the case though.

It appears that only for some points in front of the tank it chooses to rotate the long way around. Also when it’s flipping over it’s forward vector it wants to take the long route around for some reason.

This gets covered quite far down the road, when making the mortars but if you want to fix it now:

instead of

if (DeltaRotator.Yaw < 180)

in the AimingComponent::MoveBarrelTowards function, change it to

if (FMath::Abs(DeltaRotator.Yaw) < 180)

Awesome, that worked. Thanks.

It’s not that I’m not patient enough, it’s just that I saw Ben’s tank do the correct rotation while not mentioning it once that got me confused.

Pretty sure Ben’s has the same problem, I remember pointing it out to him that it happens with his repo as well at the time.

Yeah the odd thing is I couldn’ t find any fix in his code, yet in the videos it’s behaving the proper way. :slight_smile:

Privacy & Terms