- Home /
how do i make a vector into a quaternion
else{transform.rotation = Quaternion.RotateTowards(transform.rotation, randomvec, turnrate);}
i have a var randomvec set to a randomly generated vector every 5 seconds, i want to make the vector into a Quaternion so the transform can rotate towards it, i can't think of any way to do this, and would like a method or an alternative to this, thanks for the help in advanced.
Oh yeah, one other thing- is the vector a direction, or a 3-axis angle? You didn't specify.
Answer by syclamoth · Mar 15, 2012 at 03:59 AM
Because of gimbal-lock problems, there is no way to perfectly convert a Vector3 into a Quaternion. Because Quaternions actually contain more information about an object's rotation than a Vector3 ever can, you will always lose data.
Of course, if you make some assumptions about how your object should act, it's easy enough to fake it.
If you use Quaternion.LookRotation, it will return a quaternion that accurately looks towards the specified vector, always keeping the head pointing towards the 'up' vector. In most cases this is exactly what you want.
Quaternion.LookRotation(randomvec, Vector3.up);
Of course, if you just want a random Quaternion, you can always just use Random.rotation...
Answer by Eric5h5 · Mar 15, 2012 at 03:57 AM
Quaternion.Euler is for making 3 float values (represented by a vector3) that represents a quaternion, like in the inspector, into a quaternion value. Quaternion.LookRotation is for converting a vector (also represented by a vector3) but representing a direction, not a rotation, into a quaternion value that points in the same direction as the vector.
Your answer
Follow this Question
Related Questions
moving between two points over time 1 Answer
Sum Of Two Motions? 0 Answers
Distance won't work 1 Answer
postion that is small number rounded to 0? 1 Answer
Clamp X position of object 1 Answer