Hola, estoy teniendo problemas para hacer la animación de correr.
El problema aparece cuando quiero cambiar de dirección mientras el personaje está corriendo, parece que al ser tanta velocidad, el personaje resbala por el suelo.
Tengo dos vídeos, en uno la velocidad es baja y en otro es alta.
VÍDEO 1: https://gyazo.com/1dd3dd4ba68fe6eceffd2b1ced6b9284 (https://gyazo.com/1dd3dd4ba68fe6eceffd2b1ced6b9284)
VÍDEO 2: https://gyazo.com/0b4c855937572048ce4d4e3f6dcbdc5b (https://gyazo.com/0b4c855937572048ce4d4e3f6dcbdc5b)
Aquí os dejo el código que estoy usando.
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