- Home /
Animation events are still executing after transitions
Hey folks, I'm trying to add in flinching to my project. For example, you do a slow attack and an enemy does a fast attack. The fast attack hits you and cancels your slow attack.
However, I can't seem to get the transitions right. Currently I'm testing by automatically cancelling an attack as soon as it happens. I have a transition back to the idle state, 'Has exit time' false, so it should automatically go back to the idle state. However, the animation event is still executing the onAttackHit functions.
This would mean that even if I cancel the animation properly, it will still do damage, even if the animation never showed your character hitting.
What am I missing?
Can you post the code for your OnHitAttack please?
Answer by Chimer0s · Apr 08, 2018 at 10:50 PM
What's the transition time set to for the transition back to the idle state? Depending on how quickly it happens and how quick the attack animation is, there might still be some overlap. You can try to set the transition time to something very short like 0.01, but this might give you a very abrupt transition. One way to handle this would be to set a bool in your attacking script that is set to true when the attack animation begins but can be set back to false if the attack is interrupted. Then, have the onAttackHit function check to see that the attacking bool is true before executing it's code.
transition time is set to 0. The one issue I have with a script solution is if the I decide to interrupt the attack to do another attack. If the isInterrupted flag is set to true still for the second attack, then it too will not do damage. It seems to me that the Animation Events should not be executed on transitions.
I don't see how that would happen. In the case I presented, you'd simply set the attacking bool back to true when the new animation begins. But, I agree that it's beside the point as the event should not be triggered to begin with if you have a transition time of 0. Curious.