Add Torque to physics controlled player, to return roll to zero

As the player flies a simple physics aircraft around (pitch and yaw driven by Add Torque), I’m trying to use a PID controller to also Add Torque to roll to constantly return the player’s roll to zero.

My PID seems to be working fine, but I can’t figure out what Error value to feed into the PID controller. Ideally, I’d like to use a vector float that expresses roll, and not a rotator (to avoid +/-180 flipping).

Jubilation! Four days later, I figured it out. It’s so flipping obvious with hindsight :slight_smile:

The PID worked perfectly, but the tutorial I followed was designed for throttle input. So the error range for which would be 0 to 1. I needed it to constantly correct my physics pawn’s roll to zero, so the error range would be -1 to +1 (expressed as an element of a normalized vector) or -180 to +180 (expressed as an element of a rotator).
image

Once I adjusted this, I used the z value of the actor’s right vector (imho vectors are more robust than UE’s quirky rotators) to feed in a the error that the PID corrects.

I’d like to give HUGE kudos in a shoutout to Chuck Noble, Tech Director at both Fun Dog Studios and Gamergenic for his incredibly-detailed-yet-easy-to-follow post on how to do a PID in UE5 in both BP and C++.

1 Like

One thing to be aware of, I’m not sure that the Z-value of the actor’s right vector represents roll in vector form… so please double-check this.