- Home /
Getting angle offset from up vector in quaternion
What's the best way to get an offset angle from a specific axis, specifically up, from a vector3, and get it in a quaternion.
Essentially trying to do something like this
Vector3 - (0,10,0) = angle offset of 0, because its straight up
Vector3 - (1, 10, 3) = angle offset x, relative to up
What's the best way achieve this? I know its probably simple but I have no idea where to start. Thank you in advance
Answer by fafase · Aug 20, 2012 at 05:31 AM
I think you are looking for http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.FromToRotation.html
function Update () {
var angle :Quaternion = Quaternion.FromToRotation (fromDirection : Vector3, toDirection : Vector3) ;
}
that would be how to convert from vector to quaternion.
i'm not sure exactly what he means by the angle offset though.
Is he saying he wants to basically create a new angle and have that angle be based on this original one? So that basically the original becomes angle 0,0,0 even though it might really be 10,10,10 and the new one is relative to that? In that case he'd want to store the original and new x = original.x + change. Basically the new angle needs to not be the change + 0 (which is the starting point of a normal angle) but change + original x
$$anonymous$$mm,the way I get it he wants to get a vector to another vector and that in Quaternion and I guess that would be the way. Well, he will let us know if that was not it, but you put the doubt now...
Thank you, Quaternion.FromToRotation worked perfect! I was over complicating things, this function solved my problem. All I had to do was do a FromToRotation(Vector3.up, position), and my up vector was locked to position.
Thanks for the help!