I’m trying to move an object only in X axis by using the following code:
var speed = 5.0;
function Update () {
transform.Translate(0 , 0, speed * Time.deltaTime );
}
the problem is when I run the game (Play) and check the position in the inspector I can find that only Y axis position is set to 0, but X value get change although I did set it to 0 inside my translate code, any idea why this happen with me?
Also, the movement isn’t relative to the world, it’s relative to the object. As such, if the object is rotated in any way, you won’t move the right way.
So, use transform.Translate(Vector3(0,0, speed * Time.deltaTime), Space.World);