How the Quaternion Works?

Somebody can explain me what its a Quaternion, and how can i use it to rotate my 3d objects? I really frustated about it, and a i need it for a project i actually doing to the college. Thanks…

use eulerangles instead, those take a vector3.

quaternion is some black magic that requires a masters degree in mathematics to comprehend

A quaternion is actually quite simple. Imagine a vector in any direction as an arrow. That vector can be defined by XYZ. Any vector that is not 0,0,0 will do. It can be of any length that doesn’t matter the direction matters. Now that we have the direction imagine that the arrow is actually an axis which we can rotate around. Now the last the component of the quaternion is the angle. In this way we can rotate in any direction in 3D and we do not have to worry which axis we rotate first like you do with euler angles (gimbal lock).

var rot = Quaternion.identity;
rot.eulerAngles = Vector3(0,90,0);

now rotation is a quaternion and you can use it in place of transform.rotation

transform.rotation = rot;

that will rotate your object 90 degrees on the Y axis…

SimonAlkemade is about right. if you can don’t use Eular Angles, there gimbal lock problem is harder to over come then getting used to quaternions.

Get a good book I recommend: 3D Math Prime (from Fletcher Dunn and Ian Parberry)

LOL

When I first started programming in Unity I always used to spell it Quarternion.
And then wondered why the hell Unity was complaining.
Please tell me others out there thought it was spelled like this too :stuck_out_tongue:

Also check out