Announcement

Collapse
No announcement yet.

Cursor location in World Space, LookAt rotation and Gimble lock.

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

    Cursor location in World Space, LookAt rotation and Gimble lock.

    Hey guys,

    I am running into the Gimbal lock issue.

    A bit of background info, I am currently getting the cursor location in the world space (Find LookAt rotation End) and LookAt rotation Begin is the Actor Location.

    This value then goes into a Rinterp which then goes into a SetActorRotation.

    For the most part it works until I ran into the typical Gimbal Lock issue where the ship start spinning out of control when reaching 90 and - 90 Pitch.

    I tried a bunch of solutions and none work. Any help or advice would be appreciated.


    #2
    As it turns out, it seems using SetActorRotation is the offender. If I use AddActorRotation, the Gimble Lock is a non problem. However adding the Mouse world location with lookat rotation totally spazes everything out so either way it's still broken.

    Any suggestions?

    Comment


      #3
      The look at rotation you are finding is in world space, you would have to transform it to local units to apply it locally.

      or, maybe, just find the look at rotation between the mouse and the Local position of the object.
      technically that should give you a value that is already in the correct range.

      Another thing. Maybe it's not spazzing out, maybe the rotation of the mouse click has a different orientation then the local rotation of the object...

      Comment


        #4
        If you do need to solve the gimbal lock problem, here's the solution I use in my projects. Since the problem keeps coming up and it may help others...
        The macro below is to be used to find the rotator to add to your current rotator to make it from its current forward vector to a new forward vector bypassing the gimbal lock.
        Click image for larger version

Name:	Gimbal-Fix.png
Views:	54
Size:	163.0 KB
ID:	1733232

        Comment


          #5
          Originally posted by MostHost LA View Post
          The look at rotation you are finding is in world space, you would have to transform it to local units to apply it locally.

          or, maybe, just find the look at rotation between the mouse and the Local position of the object.
          technically that should give you a value that is already in the correct range.

          Another thing. Maybe it's not spazzing out, maybe the rotation of the mouse click has a different orientation then the local rotation of the object...
          This is with SetActorRotation
          https://i.gyazo.com/82fff50e1e4d9154...fc678c9f02.mp4


          This is AddActorRotation (spazzing)
          https://i.gyazo.com/4730dec7b85ee036...50ed194cbc.mp4

          This is AddActorRotation but with LookAt values transformed from World to Local
          https://i.gyazo.com/fe6ecc85b3be8d45...6c8d0d2391.mp4

          So, it definitly did something, but really just put me back to the initial scenario with Gimble Lock.

          Comment


            #6
            because you are dealing with a flying vehicle, I would suggest just using the quaternion C++ library. It's much easier to implement too, since it's pre-packed and allows you to set the local rotation via a quaternion calculation instead.

            You don't necessarily need to purchase it on the marketplace either, there's a free one floating around on this forum that I have shared before...

            ha, here's a link
            https://forums.unrealengine.com/deve...46#post1644046
            Last edited by MostHost LA; 03-16-2020, 11:12 AM.

            Comment


              #7
              Originally posted by MostHost LA View Post
              because you are dealing with a flying vehicle, I would suggest just using the quaternion C++ library. It's much easier to implement too, since it's pre-packed and allows you to set the local rotation via a quaternion calculation instead.

              You don't necessarily need to purchase it on the marketplace either, there's a free one floating around on this forum that I have shared before...

              ha, here's a link
              https://forums.unrealengine.com/deve...46#post1644046

              Hey, thanks for actually taking the time to help me out, I really do appreciate it.

              Funnily enough, I found that post of yours while trying to use Quaternion (It was the first thing I thought off to bypass the typical Euler Gimble Lock issue). I succesfully tried with basic input to set the rotation (and of course there was no Gimble lock problems) but I think it all goes to **** when I use the LookAt function to set the rotation.

              LookAt does work, but with limitations but I think one of my logic is flawed or how I applied my rotations must not make sense. Using LookAt with Quats is even worse in my case.

              Click image for larger version

Name:	problem.png
Views:	51
Size:	80.0 KB
ID:	1733396

              The BP_Cursor is just a blueprint that casts to what's under the cursor, this works as demonstrated previously. Following the the previous advice, I translate from world space to local the LookAt return Value and turn it into a Quat, which is then adds to the Local Rotation (Quat). I wonder if it had a set rotation ( quat ) would it have the result I want.

              Anyways, yeah, it still doesn't work this way, I think it's probably lost when transforming to local then to quat? even without transforming its the same result (ship spazes out).
              I am not sure I mentioned, but what I try to achieve is essentially the ship follows the cursor.

              Any insight to help me get better logic would be appreciated.

              Comment


                #8
                No further advice unless I actually go and do it I'm afraid.
                I think the issue is how you are getting the cursor position.

                Why not simplify it and just add +1 if the mouse is the the left, -1 if to the right. etc. ?
                You could even end up driving this by the distance of the cursor on the screen - so the further it is, the faster the turn rate
                to do that
                cursor location x / screen size x = - the screen position in 0 to 1 range.
                From the 0 to 1 range just set up a set of >= .25, .5, .75 - and instead of just a +1 you +1, +5, +15...

                if done correctly it should work fine on both axis - and the object axis you want to affect are probably Z for left to right, and X for up and down.

                Comment


                  #9
                  This wouldn't really be following the cursor though I think. A simple way of actually going around this and not using the cursor or mouse and simply having WS for Up/Down And AD for Left/Right.

                  I was trying specifically to get that freelancer feeling but I think your idea is actually a pretty clever work around. I got started on it and I am effectively reading the cursor position from a 0 to 1 range, will come back with update when I can.

                  Thanks for not giving me the solution, it's actually helpful understanding logic and getting better.

                  Comment


                    #10
                    As an update, this is currently what I have:Click image for larger version

Name:	workaround.PNG
Views:	32
Size:	92.9 KB
ID:	1733473
                    and I directly feed the X and Y mouse axis value to both the X and Y Speed. This works, however, it is not what I wanted but I'll take small victories. I think I will do the cursor being farther away thing as well tho.

                    Any suggestions of a better implementation?

                    Comment


                      #11
                      Sure. I assume the Mouse Movement event is called on click?

                      If you create Axis events for the mouse - it pretty much works OnTick without being an OnTick function.

                      Mouse constantly moves.
                      As such, you can get the X or Y direction from the respective Axis value.

                      Which brings to yet another way to implement it - simply add the axis value scaled (multiply) but a custom speed variable into the rotation.

                      Personally, I branch at the start and if axis is == 0 I stop the execution. But you may actually want to re-apply whatever the latest value was instead, don't know.
                      It would make you pan back to the center when you stop moving the mouse.

                      Maybe it's closer to what you want that way.

                      Comment


                        #12
                        Originally posted by MostHost LA View Post
                        Sure. I assume the Mouse Movement event is called on click?

                        If you create Axis events for the mouse - it pretty much works OnTick without being an OnTick function.

                        Mouse constantly moves.
                        As such, you can get the X or Y direction from the respective Axis value.

                        Which brings to yet another way to implement it - simply add the axis value scaled (multiply) but a custom speed variable into the rotation.

                        Personally, I branch at the start and if axis is == 0 I stop the execution. But you may actually want to re-apply whatever the latest value was instead, don't know.
                        It would make you pan back to the center when you stop moving the mouse.

                        Maybe it's closer to what you want that way.
                        Yeah it was mostly to test, it has it's own independant event now.

                        As for the axis branch, I actually use that for other inputs to avoid needless ticks.


                        Comment

                        Working...
                        X