- Home /
rigidbody.MoveRotation neither world space or local? How does it work?
Hi, I have a script that is supposed to change the rigidbody along the X or Y axis depending on what mouse button you press. But the Y axis rotation seems to be in world space and the X axis it seems to be in local space. How do I get the whole thin in world space? (I need to use rigdbody.MoveRotation and not transform.EulerAngles because of strange collision events.)
Here is part of my script:
if (Input.GetMouseButton (0) && Time.time > nextRot) {
nextRot = Time.time + rotRate;
rotX = rotX + 90;
if (rotX > 315) rotX = 0;
if (rotX >= 225 && rotX < 315) rotX = 270;
if (rotX >= 135 && rotX < 225) rotX = 180;
if (rotX >= 45 && rotX < 135) rotX = 90;
if (rotX >= 0 && rotX < 45) rotX = 0;
Debug.Log ("rotX = " + rotX);
xCanRot = true;
}
else xCanRot = false;
if (Input.GetMouseButton (1) && Time.time > nextRot) {
nextRot = Time.time + rotRate;
rotY = rotY + 90;
if (rotY > 315) rotY = 0;
if (rotY >= 225 && rotY < 315) rotY = 270;
if (rotY >= 135 && rotY < 225) rotY = 180;
if (rotY >= 45 && rotY < 135) rotY = 90;
if (rotY >= 0 && rotY < 45) rotY = 0;
Debug.Log ("rotY = " + rotY);
yCanRot = true;
}
else yCanRot = false;
if (yCanRot || xCanRot) {
blockRotation = Quaternion.Euler (Vector3 (rotX,rotY,0.0));
rigidbody.MoveRotation(blockRotation);
}
Answer by DFLY · Oct 19, 2014 at 02:30 PM
I think I have figured it out. I was using Euler Angles and they (I think) rotate in a sequence of axis and can change the Euler angle values as they go. I have used them very effectively before for rotation about a single axis (A dial from one to 10). But they are really bad for incrementing movement in 3D.
Now for this project, I am using Transform rotation as below:
#pragma strict
var canRot: boolean;
private var emptyRotation: Quaternion;
function Start () {
canRot = false;
emptyRotation = Quaternion.identity;
}
function Update () {
if (Input.GetMouseButtonDown (0) ) {
transform.Rotate (Vector3.right * 90 , Space.World);
}
if (Input.GetMouseButtonDown (1) ) {
transform.Rotate (Vector3.up * 90 , Space.World);
}
emptyRotation = transform.rotation;
}