Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Avoiding Gimbal Lock in rotations between vectors?

Hello all, thank you for considering my question.

I have read a lot of questions on Gimbal Lock but none of them covered a situation with the involvement of vectors.

Description: I have two spheres that are moving in a random path (used timelines for that) and the spheres represent two VR hands. The object that is in the middle is irrelevant, it's just a mesh.

Goal: What I'm trying to do is to calculate the rotation that an object between the two spheres needs to rotate using only the two spheres.

Current Approach: The basic idea that I'm building upon is creating a vector from sphere 2 (white) to sphere 1 (red) then saving it, and in the next frame, I'm calculating the vector's new position and comparing it to the saved one to get the rotational difference. I'm using Rot from XY node to get the Yaw and Pitch, and Rot from ZX to get the Roll.

Current Problems: The blueprint seems to be doing fine, except for the Gimbal Lock effect that happens with the Roll element at a certain degree (check GIF).


  1. Do you think there's a way to fix this problem without changing the basic approach to the problem (check my failed solution attempt in the Gimbal Sol function blueprint)
  2. If you have any experience with quaternions, please share details on how you would use them in this case, and try to be as clear as possible (I have no experience with quaternions). Keeping in mind that we're using 2 vectors to calculate the rotation.

P.S.: You can check the blueprint for this GIF, it's attached, but it has a lot of trial and error nodes in it, so it might be slightly tedious.

I thank you again for your time.

Max. alt text alt text

Product Version: UE 4.18
handsblueprint.png (306.6 kB)
gimbalsolfun.png (123.6 kB)
more ▼

asked Feb 22 '18 at 09:32 AM in Blueprint Scripting

avatar image

9 4 4 5

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

If I understand correctly, you are trying to orient an object along the vector between the two spheres. I haven't used quaternions in Unreal, but what I think you need to do is convert the rotation to a quaternion by getting the rotation as an axis and angle. To get the axis of rotation, take the cross product of the two vectors (after normalizing them). The resulting vector will be orthogonal to the two original vectors, and its length will be proportional to the sine of the angle between them.

Actually, I just saw that FQuat has a function to create a quaternion from two vectors (in C++). Not sure if there's an analagous function in blueprints.

more ▼

answered Feb 22 '18 at 09:46 PM

avatar image

51 2 6 7

avatar image Maxorian Feb 24 '18 at 11:03 PM

So while there's no "FQuat" node in blueprints, I found a MakeQuat node that returns a variable type Quaternion. But I have no idea as to how to translate that into a rotation.

But there's still the problem that for some reason the angle between the two vectors is always coming up as 0 when I was trying to use Rotator from Angle and Axis....

avatar image Maxorian Feb 24 '18 at 11:26 PM

Nevermind! I just realized that one of the normalize nodes was not connected.... It works perfectly, thanks man!alt text

handsblueprint.png (227.2 kB)
avatar image Tuxmask75 Feb 14 '19 at 04:38 AM

Hey if you print this to screen, while rotating the Y Axis , do the numbers jump all over the place? or are they consistent from 0 to 360? Looking for a solution where I can Rotate all 3 Axis and have consistent numbers.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question