Hello, (sorry, if my English is bad I'm German) I started learning unity and programming a few days ago. I followed the Brackeys 2d game tutorials but now I'm stuck. When I add a animator the player is facing right when I move right and also when I move left. Before I added the animator everything was working fine. The only difference I made to Brackeys game is that I used the built in animation function and Brackeys is using a sprite animation and I used the same code. script: Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class playermovement : MonoBehaviour { public CharacterController2D controller; public Animator animator; public float runSpeed = 40f; float horizontalMove = 0f; bool jump = false; bool crouch = false; // Update is called once per frame void Update() { horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; animator.SetFloat("speed", Mathf.Abs(horizontalMove)); if (Input.GetButtonDown("Jump")) { jump = true; } if (Input.GetButtonDown("crouch")) { crouch = true; } else if (Input.GetButtonUp("crouch")) { crouch = false; } } void FixedUpdate () { // Move our Character controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump); jump = false; } }
Moin Lennart, you have to flip your character. You can do that in different ways, here is one: Create a bool Code (CSharp): private bool isFacingRight = true; In Update, after you get youre horizontal move Code (CSharp): if ((horizontalMove < 0f && isFacingRight) || (horizontalMove > 0f && !isFacingRight)) { isFacingRight = !isFacingRight; transform.Rotate(0.0f, 180.0f, 0.0f); }