To ensure that an animation is not set if it's already playing, you can check the current animation on track 0 before setting a new animation. This can be done by comparing the animation name of the currently playing animation with the name of the animation you intend to play. If they are not the same, then you set the new animation. Here's how you can modify your code:
// Assuming walkEAnimation is a string containing the name of the walking animation.
TrackEntry currentEntry = angieSklAnim.AnimationState.GetCurrent(0);
if (currentEntry == null || currentEntry.Animation.Name != walkEAnimation) {
if (!isRolling) {
track0Entry = angieSklAnim.AnimationState.SetAnimation(0, walkEAnimation, true);
}
}
This approach avoids unnecessary string comparisons when the desired animation is already playing and prevents the animation from restarting each frame. It checks if there's currently an animation playing on track 0 and if the name of that animation is different from the one you want to play. If both conditions are met, it sets the new animation. This method is efficient and straightforward, ensuring that your animations transition smoothly without unnecessary restarts.