I'm currently learning and developing a 2D plataform game in Unity, but now i'm having some errors that i can't solve.

When I press the arrow keys to make my character move right and left, the Z axis is being incremented somehow,and the player is "getting into the screen", even though I didn't write anything about it in my script.

I read about the "Apply Root Motion" in the Animator segment, and I unmarked it as they said, but I think the error might still be there, but i'm not sure.

Does anyone know about it?

Here is a snippet of my code:

void Movement() {
    anim.SetFloat ("speed", Mathf.Abs (Input.GetAxis ("Horizontal"))); //Makes it record a value of speed between -1 and 1, so that the trigger of the animation can work.

    if (Input.GetAxisRaw ("Horizontal") > 0) {
            transform.Translate (Vector3.right * speed * Time.deltaTime);//speed * Time.deltaTime makes things smoother, it updates frame by frame, so that it does not jump all around 
            transform.eulerAngles = new Vector2 (0, 0);

    if (Input.GetAxisRaw ("Horizontal") < 0) {
            transform.Translate (Vector3.right * speed * Time.deltaTime); 
            transform.eulerAngles = new Vector2 (0, 188);
  • \$\begingroup\$ Are you using 3D colliders or 2D colliders? \$\endgroup\$
    – Varaquilex
    Jan 30, 2015 at 23:59

1 Answer 1


I'm gonna make a wild guess that you are using 3D colliders.

Check out the colliders of your character and make sure you froze rotation and Z transformation so that your character will not rotate or bounce in Z direction upon a collision.

  • \$\begingroup\$ 2D colliders! But i found the solution, it's in the transform.eulerAngles = new Vector2 (0, 188); It's not 188, it is 180! 188 is making him go foward in the Z axis. Thank you! \$\endgroup\$ Feb 1, 2015 at 18:38
  • \$\begingroup\$ Oh, right. I missed that one. \$\endgroup\$
    – Varaquilex
    Feb 1, 2015 at 18:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .