Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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?

    Click image for larger version

Name:	rotation1.JPG
Views:	1
Size:	93.4 KB
ID:	1217816
    Click image for larger version

Name:	rotation2.JPG
Views:	1
Size:	82.0 KB
ID:	1217817

    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.

    roll = Mathf.Atan2(2*y*w + 2*x*z, 1 - 2*y*y - 2*z*z);
    pitch = Mathf.Atan2(2*x*w + 2*y*z, 1 - 2*x*x - 2*z*z);
    yaw = Mathf.Asin(2*x*y + 2*z*w);
    I hope it is correct.
    Click image for larger version

Name:	macro.JPG
Views:	2
Size:	175.1 KB
ID:	1217821
    Attached Files
    Last edited by Mewbits; 05-06-2017, 05:36 AM.

    #2
    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
    https://www.youtube.com/watch?v=SVWHXrwVWnU
    Last edited by redbox; 05-06-2017, 03:16 AM.
    Rocketeer

    my portfolio
    my youtube

    Camera Volumes System
    Instanced Plugin
    Simple Portals
    Water Flow For UDK
    Setup Swarm

    Comment


      #3
      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.
      Last edited by Mewbits; 05-06-2017, 03:09 AM.

      Comment


        #4
        Originally posted by redbox View Post
        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
        https://www.youtube.com/watch?v=SVWHXrwVWnU
        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).

        Comment


          #5
          Originally posted by ZoltanE
          Here is a RotatorToQuat blueprint macro for those of us who do not know c++:
          http://zspline.net/files/RotatorToQuat.uasset
          I just found another forum thread, in which ZoltanE, UE4 staff provided a Rotator to Quat Macro.
          Now I just need to find a Quat to Rotator macro too. lol

          Click image for larger version

Name:	rotator.JPG
Views:	1
Size:	61.3 KB
ID:	1127362
          Last edited by Mewbits; 05-06-2017, 03:55 AM.

          Comment


            #6
            That's not entirely true. You can make and break Quaternions.
            And? Can you make operations with them without breaking on components?

            Also what is pcm?
            I used character class and player camera manager.
            Rocketeer

            my portfolio
            my youtube

            Camera Volumes System
            Instanced Plugin
            Simple Portals
            Water Flow For UDK
            Setup Swarm

            Comment


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

              roll = Mathf.Atan2(2*y*w + 2*x*z, 1 - 2*y*y - 2*z*z);
              pitch = Mathf.Atan2(2*x*w + 2*y*z, 1 - 2*x*x - 2*z*z);
              yaw = Mathf.Asin(2*x*y + 2*z*w);
              Click image for larger version

Name:	macro.JPG
Views:	2
Size:	175.1 KB
ID:	1127672

              Comment

              Working...
              X