I’m trying to use Quaternion.FromToRotation function to calculate the exact difference in Euler angle between two objects.
I converted the Quaternion by multiplying the simple direction vector to be used as a parameter.
(How can I convert a Quaternion to a direction vector? - Questions & Answers - Unity Discussions)
But I couldn’t get exact angle difference.
Here is code and screenshot.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestQuaternionFromToRotation : MonoBehaviour
{
public Transform fromTransform;
public Transform toTransform;
public Vector3 fromVector;
public Vector3 toVector;
void Update()
{
fromVector = fromTransform.rotation * Vector3.up;
toVector = toTransform.rotation * Vector3.up;
transform.rotation = Quaternion.FromToRotation(fromVector, toVector);
}
}
I expected (20, 40, 60), of course, but the results were different.
What’s wrong with this script?
Is it related to Gimbal Lock?