Solution to avoid Gimbal Lock for Twist Joints using Blueprint

Hi all,

As of may know, there’s not solution to avoid Gimbal Lock using Blueprints, so the alternative is to use C++.

I tried a different approach to solve this issue, and I came up with a working solution in order to solve Gimbal Lock when using Twist Joints.

On the left you can see the X hand_l rotation value flipping between -180 and 180, while on the right you see that there’s no flipping and the value goes over -180/+180.

The setup is as follow:

  1. If the value is >0 and <180 the data is read from the X hand_l rotation and I use a DoOnce to set a boolean to true.
  2. The boolean sets itself false and reset the DoOnce if the value is <0 and >-90.
  3. I then use a Map Range Clamped node, that gets the X hand_l rotation data, checking if the value is in range of -180 and -90, which then output 0 and 90.
  4. The output of this node is then added to 180.
  5. I then use the Select Float node to switch between the X hand_l data to the Map Range Clamp node output.
  6. Finally I scale the output by multiplying by a float ( set to 0.75 or 0.5 ) to transfer the rotation amount to the lower arm twist joint.

The same logic is used when the X hand_l rotation data is <0 and >-180.

Problem solved :slight_smile:

Regards,
Nicolas

4 Likes