Gimbal Lock and Controller Input Inconsistency

[TLDR (Video of issue)][1] and screen shots of data below.

I’m having a problem with controller and pawn relationship.

Essentially, it’s a blueprint only game. I’ve taken the Flying Template and the Gunslinger multiplayer example and spliced them together with my own game concept. It’s a multiplayer space flying and shooting game.

As a space flying game, there’s no up. Up is relative. I was using the input control from the Flying Template (add local translation. Add local rotation). This replicated horribly as the ships were stuttering around the level in a multiplayer game. Based on research it was clear that I need to use Add Movement Input and Add Controller Roll, Pitch, Yaw Inputs as they replicates under the hood much better.

So I’ve set that up and it does replicate perfectly. However, I’m running into two huge issues.

The Roll is relative to the pawn, but it appears the Pitch is not. How do I make Pitch relative to the pawn’s orientation?

Gimbal lock is preventing me from smoothly crossing the 180 line on all axes (just using Roll and Pitch). Add Local Rotation got around that pretty nicely but didn’t replicate well. How do I get around Gimbal Lock using Add Controller Pitch and Roll Inputs? (Also in VR when you hit Gimbal Lock using a gamepad the view goes bananas, each eye shows something different. Interestingly enough Gimbal Lock in VR with a keyboard doesn’t seem to occur)

I’m just looking for some consitency and a resolution for the right way to go about this. Attached are images that show the input scripts in the Pawn, the Pawn defaults, and the PC defaults.

Also, here is a video that describes the problem. I greatly appreciate any insight!!!

There really is only one way to solve this and that is to use quaternions. They operate in 4D space so there is no gimbal lock there.

Skipping the complicated math, all you have to do is to generate a rotator based on the input that your controller gives and then add that rotator to the current rotator of the actor. Translation is done as per normal.

I will update with an image when I can find the image I uploaded. EDIT: Cant find it. so I made one.

http://puu.sh/rrdKj/3a4b5deabc.png

This should fix all your problems, but you have to use the correct rotator. If you use the ships rotation you have to rotate around the foward vector and the up vector. The up vector might cause a problem where you cant go upside down, so make sure that your up vector is set to -1 when you are upside down.

I actually got lucky and seemingly fixed the Gimbal lock issue by creating a custom Camera Manager Class, and setting it’s defaults to…

For some reason you can’t just set those values to 360, it won’t move at all that way.

And I still need to figure out why the pitch input isn’t relative to the pawn.

I updated my answer with some more info. Try what I wrote and tell me if it worked.

I’m not directly setting the rotation because that doesn’t replicate smoothly in a multiplayer game. I have to use the Add Controller Pitch Input. Which essentially takes the input directly from your input event (keyboard / gamepad / etc). It works, but it’s just not reflecting the pawn’s rotation like the Add Controller Roll Input is. It’s that inconsistency that I don’t understand.

So UE4 really DOES have quaternions in blueprints? I also want to make a 6DoF game so i want to try this out! Are there any other nodes that use quaternions I should know about?

This doesn’t resolve gimbal lock problem. Having reversed camera when upside down is a symptom of a gimbal lock, it’s engine way to try and resolve that by fliping camera.

Hi CharlieTheTall,

i´m working on a space game too and ran into the same problem. So i read the possibility to add a custom PlayerCameraManager BP, but i don´t know what to do after create it and settting the default variables? Could you go deeper into it or do you maybe have a better solution?

Best regards, Darkentik