- Home /
Vector 3 coordinates confusion (transform.Translate(...))
I'm confused about something unity does when i type the following into the editor (javascript):
if(MainMenuGUI.difficultyDisplay=="hard"){
gameObject.transform.Translate(0,0,-5);
}
The problem is the second line, the line the if statement has to execute if the condition is true. I'm basically moving an object 5 units back on the z-axis, however when i test it, the object moves vertically down 5 units (y-axis). I then modified the line:
gameObject.transform.Translate(0,-5,0);
and it worked the way I wanted it to. However, I have no idea why, hope one of you can clear this up! thanks :)
Answer by Piflik · Jan 02, 2013 at 07:59 PM
transform.Translate uses local coordinates by default. If you want to move an object in world coordinates, write transform.Translate(0, 0, -5, Space.World)
Answer by Eric5h5 · Jan 02, 2013 at 08:07 PM
Translate uses Space. Local by default, so if the object is oriented so that it's pointing up, then moving it back 5 units along its z axis will make it move down 5 units. You can use Space.World instead, or just move it down 5 units in the world by doing "transform.position.z -= 5". (As an aside, I'd recommend not using strings unless necessary, so difficultyDisplay should use something else like an enum.)
Your answer
![](https://koobas.hobune.stream/wayback/20220613090256im_/https://answers.unity.com/themes/thub/images/avi.jpg)