Triggered Animation playing twice, instead of only once
Hi everyone
I'm having a weird issue, that apparently many people have as well, but I could not find a working solution yet.
Basically, I wanna make a Plant wiggle when my player touches it. I made a short animation clip for that, and an Animator on the plant game object that transitions to the wiggle animation when a trigger is set (condition on entry transition), and returns after. It works, however, about half of the time, the animation plays twice instead of only once even after the trigger isn't active anymore. It's really weird, judging from the Animator UI, it transitions back to idle for a split second, then goes back to the wiggle again to play it once, without the trigger becoming active again.
Most solutions online suggest that it has to do with the exit time for transitioning back to the idle state, however I have set the exit time to 0. The entry transition is also set up correctly, with the Wiggle trigger as a condition. The animation is definitely also set to not loop. Some also suggested that it has to do with the animations short duration, however making it longer doesn't change anything, it just postpones the repetition.
Here's a short video showing the issue: https://youtu.be/OJ2ZQEnveoQ as you can see the "CurlPlantWiggle" Animation plays again, transitioning to "CurlPlantIdle" for a vey short moment, then playing "CurlPlantWiggle" again, without the trigger on the right being active again.
Also, here's the script I'm using on the plant to set the Wiggle trigger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlantWiggle : MonoBehaviour {
private Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
void OnTriggerEnter2D () {
anim.SetTrigger("Wiggle");
}
}
Your answer