- Home /
2D Animation Transition Bug
Hello! I have just begun learning unity. I am trying to build a 2D platformer. I have two animations: "Idle" and "Attack". I have a transition from "Idle" to "Attack" that has "Transition Duration" = 0 and "Exit Time" = 0, so that it changes instantly when I press the attack key. I also have a transition from "Attack" to "Idle" that has "Transition Duration" = 0 and "Exit Time" = 1 so that when I release the attack key, the attack animation finishes playing before returning to the idle animation
Regarding the issue: I noticed that sometimes, when I press the attack key again (exactly when the attack animation finishes) the last sprite is being displayed longer than usual. I changed the "Exit Time" from 1 to 0.5 and tried to reproduce the bug. The attack animation has 4 sprites, so most of the time only the first two are rendered. But sometimes, when I keep pressing the attack key or press it right when the first two sprites finishes, it continues to play the other sprites too.
The controller script has only a few lines:
public class SwordManAnimationScript : MonoBehaviour
{
private Animator animator;
// Start is called before the first frame update
void Start()
{
animator = GetComponent<Animator>();
animator.speed = 0.05f;
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.X))
{
animator.SetBool("isAttacking", true);
}
else
{
animator.SetBool("isAttacking", false);
}
}
}
Can someone please explain why this is happening, or if there is a bugless way to do this type of transition?