Help Needed! Understanding and Correcting Gimbal Lock in a Flying Game

In the flying template, when flying towards upwards or downwards 90 and -90 yaw, gimbal lock occurs. To experience this, first, you want to unpin “Set Current Roll Speed.” Next fly upwards (continually hold the ‘D’ key or the up arrow). You will notice a jarring flip happen while loopdy looping in the air, rather than a smooth ride. This is the gimbal lock. This occurs when two axis are rotated the same direction on the gimbal. To fix this we can use Quaternions instead of rotators, which have a fourth axis parented to the middle axis that can be used if the middle axis gets locked with the outer axis.

I have been researching how to fix this phenomenon. However, I have no idea how to correctly use Quaternions in UE4 blueprints. Here are my blueprints for setting up the rotation of my ship pawn (my ship pawn is a separate blueprint from my camera so that it can lag behind the camera). How can I incorporate Quaternions to eliminate the gimbal lock?


09f16a57f416d267240a8eda1b24a8bd97a6d1ba.jpeg

Heres a gif of the Gimbal Lock while Looping.

UPDATE:

So it turns out Quaternions are not super exposed to blueprints. However I found a Rotator to Quat Macro made by one of the wonderful staff at Epic Games. Thanks, ZoltanE!

http://zspline.net/files/RotatorToQuat.uasset

I found an equation online for making a Quad to Rotator Macro.

I hope it is correct.

There is no way to use quaternions in BPs, only in C++.
I tried similar setup in BPs. I used character class and player camera manager. In pcm you can set rotating limits, so use existing yaw values for all.
This allows character to rotate in any direction.
But, with this you can’t use camera with any smooth interpolation. It will instantly rotate camera by roll while passing pitch between 360 and 0.

Here is how it works without interpolation

That’s not entirely true. You can make and break Quaternions.

And if I can’t use it in a way that will help me fix the gimbal lock, what can I use instead?

And if you notice the gif, there’s a wobble forwards and back. I need to fix that as well. I tried removing the finterp to on the forward vector, and that did not fix it.

[QUOTE=redbox;705104]
There is no way to use quaternions in BPs, only in C++.
I tried similar setup in BPs. I used character class and player camera manager. In pcm you can set rotating limits, so use existing yaw values for all.
This allows character to rotate in any direction.
But, with this you can’t use camera with any smooth interpolation. It will instantly rotate camera by roll while passing pitch between 360 and 0.

Here is how it works without interpolationhttps://youtube.com/watch?v=SVWHXrwVWnU[/QUOTE]

So wouldn’t that just be creating a new gimbal lock if it instantly rotates at 360 and 0?

Also what is pcm? Player Character Movement? Do you mean the movement component?

I’m not using lag on my camera. Only on the flying pawn that follows it around with a slight lag (with different lag strengths in each direction).

I just found another forum thread, in which ZoltanE, UE4 staff provided a Rotator to Quat Macro. :slight_smile:
Now I just need to find a Quat to Rotator macro too. lol

And? Can you make operations with them without breaking on components?

Does anyone know if this is the correct formula for converting Quats to Rotators?