Wilku
July 28, 2016, 10:38pm
1
Hi
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;
Turret->Rotate(DeltaRotator.Yaw);
Barrel->Elevate(DeltaRotator.Pitch);
}
car1bo
July 28, 2016, 10:52pm
2
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.
ben
July 29, 2016, 10:12am
3
It is indeed addressed in a few lectures time
Tormie
January 18, 2017, 11:10am
4
I got the same issue, I know what is wrong, but not sure how to fix it
ben
January 21, 2017, 2:56pm
5
Have you tried a negative sign in front of the yaw?
Tormie
January 23, 2017, 9:08am
6
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.
DanM
January 23, 2017, 10:29am
7
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)
Tormie
January 23, 2017, 10:57am
8
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.
DanM
January 23, 2017, 11:00am
9
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.
Tormie
January 23, 2017, 11:24am
10
Yeah the odd thing is I couldn’ t find any fix in his code, yet in the videos it’s behaving the proper way.