This seems like a simple question but I couldn't get it to work. I want to rotate a game object using a quaternion, relative to world space.
I have tried this:
GameObject head = GameObject.Find("head");
head.transform.rotation = new Quaternion(0,0,0,0);
newRot = new Quaternion(xrot, yrot, zrot, wrot); //(I have the Quaternion values from mocap software)
head.transform.Rotate(newRot.eulerAngles.x, newRot.eulerAngles.y, newRot.eulerAngles.z, Space.World);
But it still seems to rotate in the object's local space.
Assigning a quaternion of (0, 0, 0, 0) may have unpredictable results. Without checking I can't tell you exactly how Unity will handle this, but if the intent is to reset the orientation to identity, assign Quaternion.identity instead.
Also, make sure xrot, yrot, zrot, and wrot are actually intended to be used as the elements of a rotation quaternion. (I'm assuming they are based on the use of the 'w' element, but it's probably worth checking nonetheless.)
Finally, I'm not sure what the behavior of Rotate() is when the object is a child object and the rotation is specified in world space. If Rotate() doesn't handle this case correctly though, you can apply the rotation directly by modifying transform.localRotation (with a little quaternion math, you can achieve the effect of the rotation being applied in world space).
Sorry if my answer is a little vague, but I'd have to check some things in order to be certain of the above answers.
It’s pretty easy:
<pre>head.transform.Rotate(xrot, yrot, zrot, Space.World);</pre>