- Home /
Question by
Sam_Pr · Apr 10, 2013 at 08:55 PM ·
javascriptlocalglobal
Problem with world coordinates in scripts?
I've been working on a little 2D test project, but I have a slight problem. when I rotate the platform it goes along local coordinates which I don't want. So I went off and found Space.World. Now when I try to add this into my script, well. I don't know where to put it.
Sorry for the stupid question.
Here's my code:
#pragma strict
var MoveSpeed:int = 20;
var RotateSpeed:int = 150;
//movement
function Update () {
if(Input.GetKey("w")){
transform.Translate(Vector3.up * Time.deltaTime * MoveSpeed);
}
if(Input.GetKey("d")) {
transform.Translate(Vector3.right * Time.deltaTime * MoveSpeed);
}
if(Input.GetKey("a")) {
transform.Translate(Vector3.left * Time.deltaTime * MoveSpeed);
}
if(Input.GetKey("s")) {
transform.Translate(Vector3.down * Time.deltaTime * MoveSpeed);
//Rotation
}
if(Input.GetKey("z")) {
transform.Rotate(Vector3.forward * Time.deltaTime * RotateSpeed);
}
if(Input.GetKey("c")) {
transform.Rotate(Vector3.back * Time.deltaTime * RotateSpeed);
}
}
Thanks for any help!
Comment
Best Answer
Answer by whebert · Apr 10, 2013 at 11:04 PM
If you want to rotate relative to the world axis:
transform.Rotate(Vector3.forward * Time.deltaTime * RotateSpeed, Space.World);
transform.Rotate(Vector3.back * Time.deltaTime * RotateSpeed, Space.World);
Your answer
![](https://koobas.hobune.stream/wayback/20220613100054im_/https://answers.unity.com/themes/thub/images/avi.jpg)