Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Delay in 2D animation (Unity 5.0.2f1)

Discussion in 'Animation' started by Kym044, Jul 20, 2015.

  1. Kym044

    Kym044

    Joined:
    Jul 20, 2015
    Posts:
    2
    Hello guys! I'm trying to animate my 2D character in unity and everything is going fine, but I'm having a little delay when I stop pressing the buttom to walk (the animation still a bit more after I stop pressing the buttom).

    Here my animation script:
    using UnityEngine;
    using System.Collections;

    public class PlayerAnimation : MonoBehaviour {

    public Animator anim;


    void Start () {

    anim = GetComponent<Animator> ();

    }


    void Update () {

    if (Input.GetKey (KeyCode.A)) {
    anim.SetBool ("Left", true);
    anim.SetBool ("Right", false);
    anim.SetBool ("Down", false);
    anim.SetBool ("Up", false);
    }
    if (Input.GetKey (KeyCode.D)) {
    anim.SetBool ("Right", true);
    anim.SetBool ("Down", false);
    anim.SetBool ("Left", false);
    anim.SetBool ("Up", false);
    }
    if (Input.GetKey (KeyCode.S)) {
    anim.SetBool ("Down", true);
    anim.SetBool ("Right", false);
    anim.SetBool ("Left", false);
    anim.SetBool ("Up", false);
    }
    if (Input.GetKey (KeyCode.W)) {
    anim.SetBool ("Up", true);
    anim.SetBool ("Right", false);
    anim.SetBool ("Left", false);
    anim.SetBool ("Down", false);
    }
    if (Input.GetKey (KeyCode.A)) {
    anim.SetBool ("WalkLeft", true);
    } else {
    anim.SetBool ("WalkLeft", false);
    }
    if (Input.GetKey (KeyCode.D)) {
    anim.SetBool ("WalkRight", true);
    } else {
    anim.SetBool ("WalkRight", false);
    }
    if (Input.GetKey (KeyCode.S)) {
    anim.SetBool ("WalkDown", true);
    } else {
    anim.SetBool ("WalkDown", false);
    }
    if (Input.GetKey (KeyCode.W)) {
    anim.SetBool ("WalkUp", true);
    } else {
    anim.SetBool ("WalkUp", false);
    }


    }
    }

    Here a screenshot of my Animator tool:


    My animation have one Idle sprite, a "start walk" sprite, and the animation that have 4 sprites, with 0,06 seconds between the sprites. Maybe someone here know what is happening?
     
  2. Kym044

    Kym044

    Joined:
    Jul 20, 2015
    Posts:
    2
    Well, I think I fixed the problem xD haha. I will put here if someone have the same problem:

    I realized that my "Walk" parameters on Animator was with a low value on speed. I increase the speed of the Walk parameters to 1.8 and now is working fine. By the way, thanks everyone!