# Transform.Translate not moving in the direction of specified vector

I’m trying to translate an object in the specific direction of a vector, however using transform.Translate seems to move it in another direction. I’m fairly certain this script works, because when I use a similar method on objects whose motion is controlled by animations it works perfectly. Printing the vector in the debugger also shows it pointing in the right direction, so I am confused as to why it isn’t working here.
In this instance, however, what usually happens is the object will move in one direction horizontally when pressing W or S, and the other when pressing A and D. Pressing a combination of W or S and A or D will result in forward and backwards motion. I’ve drawn up an example in case the explanation was hard to understand.

Any help fixing the issue would be appreciated. Here is the code in question:

``````float horizontal = Input.GetAxis ("Horizontal");
float vertical = Input.GetAxis ("Vertical");
Vector3 stickDirection = new Vector3 (horizontal, 0, vertical);
Vector3 nothing = new Vector3 (0,0,0);

Quaternion referentialShift = Quaternion.FromToRotation (Vector3.forward, cameraDirection);
Vector3 moveDirection = referentialShift * stickDirection;
if (moveDirection == nothing) return;
cube.transform.rotation = Quaternion.Lerp (cube.transform.rotation, Quaternion.LookRotation (moveDirection.normalized), Time.deltaTime * 12f);
Vector3 move = transform.forward * stickDirection.sqrMagnitude * moveSpeed;
cube.transform.Translate(move * Time.deltaTime);
``````

Please if you have trouble with any built in method you should first check the documentation.

Moves the transform in the direction
and distance of translation.

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.

So you pass in a world space direction but it’s applied in local space which doesn’t make much sense. The resulting direction would be twice the angle relative to the world forward.

So either use

``````Vector3 move = transform.forward * stickDirection.sqrMagnitude * moveSpeed;
cube.transform.Translate(move * Time.deltaTime, Space.World);
``````

or

``````Vector3 move = new Vector3(0f, 0f, stickDirection.sqrMagnitude * moveSpeed);
cube.transform.Translate(move * Time.deltaTime);
``````

ps: declaring a variable 7 constant like this “nothing” is just confusing. Just use Vector3.zero which is (0, 0, 0). For more predifined constants see Vector3

Could this object be the child of a rotated object? In such a case, the child is translated relative to its parent rotation and scale.