# Apply a Rotation in World Space based on Quaternions

 0 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. more ▼ asked Mar 23 '11 at 07:59 PM Simon 9 42 ● 10 ● 10 ● 15 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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. more ▼ answered Mar 23 '11 at 10:20 PM Jesse Anders 7.3k ● 7 ● 17 ● 48 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 It's pretty easy: `head.transform.Rotate(xrot, yrot, zrot, Space.World);` more ▼ answered May 09 at 06:13 AM MLF 1 ● 1 Or `````` head.transform.rotation = newRot * head.transform.rotation; `````` May 09 at 06:14 AM whydoidoit add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x2243
x458
x186
x139
x115

asked: Mar 23 '11 at 07:59 PM

Seen: 1762 times

Last Updated: May 09 at 06:14 AM