Caio .Vargas
Caio .Vargas

Reputation: 11

Z axis for player movement is incrementing, but i don't know why

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")));

    if (Input.GetAxisRaw ("Horizontal") > 0) {
        transform.Translate (Vector3.right * speed * Time.deltaTime); 
        transform.eulerAngles = new Vector2 (0, 0);
}

if (Input.GetAxisRaw ("Horizontal") < 0) {
        transform.Translate (Vector3.right * speed * Time.deltaTime); 
        transform.eulerAngles = new Vector2 (0, 188);
}

Upvotes: 0

Views: 78

Answers (1)

Femaref
Femaref

Reputation: 61437

transform.eulerAngles = new Vector2 (0, 188);

That 188 should be 180. Note the zero instead of an eight.

Upvotes: 1

Related Questions