Hello,
I’m new to unity and game dev. I’m working to understand unity and 2D concepts and have encountered an issue with my player’s hurt animation. When the player gets hit by spikes, the hurt animation is supposed to play. However, it often gets interrupted by the previous animation state.
Setup:
- I have a
PlayerMovement
script that handles movement and animations using Rigidbody2D physics. - There’s also a
PlayerHealth
script that manages the player’s health and triggers the hurt animation when the player takes damage. - The spikes have their own script and collider. When the player collides with the spikes, the
TakeDamage
method fromPlayerHealth
is called.
Issue:
- When the player gets hit by the spikes, the hurt animation starts but doesn’t always play fully. It gets interrupted by other animation states, regardless of the player’s current action.
Animator Configuration:
- I have transitions set up in the Animator for the hurt state.
- The hurt animation is triggered by a “hurt” trigger in the
PlayerHealth
script. - The transition from “Any State” to “Hurt” has the “Hurt” condition set up with exit time unchecked.
- The transition from “Hurt” to “Idle” has exit time checked with an exit time set to 1.
I’ve tried various solutions, but the bug persists. If anyone has faced a similar issue or has suggestions on how to fix this, I’d greatly appreciate your help!
Thank you!