Closed darkautism closed 6 months ago
I have also been trying to figure this out 😅
For my use case, I've got a series of looped tags, and I want to activate one or the other, interrupting the current regardless of how far along into the frame range it is.
I tried a number of approaches, but nothing quite worked.
Initializing a fresh Animation
and assigning it to a Mut<Animation>
seems to break playback.
The closest I got was querying for the Animation
component and setting its tag
field directly, but doing this end up playing frames from outside the tag's range during the transition.
Not sure what my options are today.
Edit: I did manage to get something working, but in an ugly way. I had to add AnimationState
to the public exports, and also mark the current_frame
field as pub.
// ....
} else if action_state.pressed(&PlayerAction::Crouch) {
if animation.tag.as_deref() != Some("Crouch") {
animation.tag = Some(String::from("Crouch"));
anim_state.current_frame = 2;
}
} else {
// ...
By setting the current_frame directly to the first frame of the tag's range, things seem to look okay.
Obviously, this is far from ideal, but it's something. Assuming there's a way I can look up the start frame of the tag I'll be unblocked, but this seems like a great use case to solve in a nicer way 😉
I merged your request and also added a new function 'play' for the animation component, that lets you switch tags more easily.
Animation::play()
is working well for me, thanks 🙏🏻
For example, I would like my character to have tags such as idle, attack, and die, and be changed by the external system when the game changes.