- Home /
why does my animations almost never play ontrigger event?
This is a problem I've been having since i started using unity and have never figured out why. When an enemy attacks my player and I want a damage animation to player its almost never works. It works like 1 in 10 times and I don't know why. The ontrigger event works fine that much I know. Below is a function to play the animation and to trigger event the functions are on seperate scripts. my SetInteger works fine because my damageState updates as intended but it doesn't transition to the damage animation in the mechanim. Also included image of mechanim and inspector. Thanks..
![void Update ()
{
if (takenDamage == true)//if player has been hit by enemy
DamagePlayer ();
else
damageState = 0;
}//end of Update()
public void DamagePlayer()
{
anim.SetInteger ("DamageState", damageState);
damageState = enemyAIScript.attackSate;
disableMovement = true;
rotSpeed = 0;
}//end of Damage Player
//___Damage Player if Hit
void OnTriggerEnter(Collider coll)
{
if(coll.tag == "Player" && enemyAIScript.e_currentState == EnemyController.AIState.ATTACKS)
{
playercontrollerScript.takenDamage = true;
}
}//end of OnTriggerEnter()][1]
[1]: /storage/temp/87795-animationproblem.png
Answer by jdean300 · Feb 10, 2017 at 08:25 PM
Most likely this is a problem in the transition settings. Depending on how your transitions and animator controller are setup, you may need to tweak the Has Exit Time, Transition Duration, and Can Transition to Self options.
Basically, I am guessing that when you try to transition to the damage animation you are at a point in the animation graph that cannot be transitioned out of and so nothing happens. Or, you may be immediately transitioning out of the damage animation state.
Your answer
Follow this Question
Related Questions
Is there a way to turn on a transitions hasExitTime on/off through code? 1 Answer
How to switch between animations instantly on 2D Blend Tree? 0 Answers
How do you remove root animation curves? 0 Answers
Animation Layer Weight Issue 1 Answer
Camera returns to starting position after playing animation 2 Answers