Search Unity

Issues with animation spamming

Discussion in 'Animation' started by BGNBStudios, Jul 10, 2021.

  1. BGNBStudios

    BGNBStudios

    Joined:
    Jul 17, 2016
    Posts:
    5
    Hello, I have a running animation imported and when I hold down A or D it works fine but I can just mash it and it looks janky. Please help :(

    Code (CSharp):
    1.  if (!m_Anim.GetCurrentAnimatorStateInfo(0).IsName("Slashing"))
    2.           {
    3.             if (Input.GetKey(KeyCode.Mouse0))
    4.             {
    5.                 if (Input.GetKey(KeyCode.D) && isGrounded)
    6.                 {
    7.                 Attack();
    8.                 m_Anim.Play("Run Slashing");
    9.                 }
    10.                 else if (Input.GetKey(KeyCode.A) && isGrounded)
    11.                 {
    12.                 Attack();
    13.                 m_Anim.Play("Run Slashing");
    14.                 }
    15.                 else
    16.                 {
    17.                 Attack();
    18.                 m_Anim.Play("Slashing");
    19.                 }
    20.             }
     
  2. KalOBrien

    KalOBrien

    Administrator

    Joined:
    Apr 20, 2021
    Posts:
    89
    In the animator click the transition and uncheck "Has exit time" for the run animation to the idle. This will remove the "jank"