Hi, I'm having trouble doing the running animation. The problem appears when I want to change direction while the character is running, it seems that being so fast, the character slides on the floor. I have two videos, in one the speed is low and in another it is high. VIDEO1: https://gyazo.com/1dd3dd4ba68fe6eceffd2b1ced6b9284 VIDEO2: https://gyazo.com/0b4c855937572048ce4d4e3f6dcbdc5b Here I leave the code that I am using. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { public float speed = 2f; private Rigidbody2D rb2d; public float maxSpeed = 5f; private Animator anim; public bool grounded; public bool pressrun; void Start () { rb2d = GetComponent<Rigidbody2D> (); anim = GetComponent<Animator> (); } // Update is called once per frame void Update () { anim.SetFloat ("Speed", Mathf.Abs(rb2d.velocity.x)); anim.SetBool ("Grounded", grounded); anim.SetBool ("PressRun", pressrun); } void FixedUpdate(){ float h = Input.GetAxis ("Horizontal"); rb2d.AddForce (Vector2.right * speed * h); float limitedSpeed = Mathf.Clamp (rb2d.velocity.x, -maxSpeed, maxSpeed); rb2d.velocity = new Vector2 (limitedSpeed, rb2d.velocity.y); if (Input.GetKey ("k")) { pressrun = true; rb2d.velocity = new Vector2 (limitedSpeed * 2, rb2d.velocity.y); } else { pressrun = false; } if (h > 0.1f) { transform.localScale = new Vector3 (1f, 1f, 1f); } if (h < -0.1f) { transform.localScale = new Vector3 (-1f, 1f, 1f); } } } Thank you very much and I am sorry for my English.
You could keep track of the direction they're travelling and if it changes, set the x portion of the velocity to zero before you apply the new force?