# Moving Object on One Axis

Hi Im trying to move some 3D text on one axis, but for some reason it moves on 2 with this code. Can someone explain why this is/ how to fix it? Maybe this is a simple solution but i cant find it.

using UnityEngine;
using System.Collections;

public class MoveTitle : MonoBehaviour {

public bool ScrollDown = false;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown("up") && ScrollDown == false)
{
transform.Translate(0.0f, -1.2f, 0.0f);
ScrollDown = true;
}
if (Input.GetKeyUp ("up"))
{
ScrollDown = false;
}
if (Input.GetKeyDown("down") && ScrollDown == false)
{
transform.Translate(0.0f, 1.2f, 0.0f);
ScrollDown = true;
}
if (Input.GetKeyUp ("down"))
{
ScrollDown = false;
}
}
}


because Translate is set to Space.Self if the Second Argument is left i would try this code below to force it to World Space

transform.Translate(Vector3.up * Time.deltaTime, Space.World);

• I ended up needing to change the Vector3 direction, but this worked. I also didn't use the Time. aspect of it seeing as I didn't need something to move over time. This is what my altered code ended up looking like. transform.Translate(Vector3.forward * 1.2f, Space.World) Commented Aug 14, 2015 at 1:43

At a guess and according to http://docs.unity3d.com/ScriptReference/Transform.Translate.html your problem might be the following:

If relativeTo is left out or set to Space.Self the movement is applied relative to the transform's local axes. (the x, y and z axes shown when selecting the object inside the Scene View.) If relativeTo is Space.World the movement is applied relative to the world coordinate system.

As far as I understand that, you translate your object according to its own x, y, z axes, which can be different from the world x, y, z axes, for example after you rotate the object.

If you wish to change the position of your object at a set location, you can simply change the local position of your transform as such:

GameObject.transform.localPosition = new Vector3(0.0f, y, 0.0f);


Note: you need to increment the y value every time the up key is pressed.

If you are attempting to see the movement of the object from Vector3(0.0f, startY, 0.0f) to Vector3(0.0f, endY, 0.0f) every time you press up, you should probably use iTween and do something like:

var position = new Vector3(0.0f, y, 0.0f);
iTween.MoveTo(GameObject target, Vector3 position, float time);


Hope it helps.

If the movement speed/direction is not multiplied by Time.deltaTime than the movement speed on different computers might be different, so it is always good to do that to ensure the speed is the same on each computer and not depending on the performance of it.