Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to unity scripting.

I am trying to move my character towards right side(on x-axis) to create a running effect, I've imported the character from blender which contains two animations, "jump" and "run". What I want to do is I want my character to move on x-axis for which I've written following code

void Update () {
    transform.Translate(5f * Time.deltaTime, 0f, 0f);

But I am facing one problem, if I set my character's y-axis rotation to 90 degrees in order to make him look towards right side I am getting strange results. That is, in play mode instead of moving towards right side(on x-axis) it move on x-axis and z-axis simultaneously & if I set the y-axis rotation to zero it behaves like I want it to. Please see the attached image for detail. How can I solve this problem?

enter image description here

share|improve this question

migrated from Mar 24 '13 at 13:02

This question came from our site for professional and enthusiast programmers.

I have suggested that a moderator migrate this to Game Development. – Pieter Geerkens Mar 23 '13 at 9:18

Use Translate overload, which takes Space enumeration values, indicating, that shift is an absolute value, like:

transform.Translate(5f * Time.deltaTime, 0f, 0f, Space.World);

or in more readable way

transform.Translate(Vector3.left * 5f * Time.deltaTime, Space.World);

Vector3.left returns a unit vector pointing left

share|improve this answer

I found the solution to my problem. And just like I thought, When Switching to my player model I had to change the movement direction from

transform.Translate(speed* Time.deltaTime,0,0);


transform.Translate(0,0,speed* Time.deltaTime);
share|improve this answer
you don't need to switch direction after each rotation. Consider setting Space.World parameter – Ilya Ivanov Mar 23 '13 at 9:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.