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).
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.
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here