#Animation-based events

2 messages · Page 1 of 1 (latest)

faint cypress
#

Hey all, new to Bevy. Wondering if anyone has any tips/suggestions for approaching animation-based events? For example, triggering an event 500ms/X amount of frames after the animation began. Is there a clean way to approach this or should I just fire both and wait a specific amount of time and hope it lines up properly?

If anyone has had to do this for their game I'd appreciate any pointers/suggestions. Game is 3D by the way.

tall cape
#

There is a large difference between 500ms/X amount of frames unless you are using a fixed timestep.
I have solved this problem (without using fixed timestep) by having a GlobalAnimationFrame resource and a GlobalAnimationTimer resource.
Sample code looks something like this ```rust
#[derive(Resource, Default)]
pub struct GlobalAnimationFrame {
pub current_frame: usize,
}

#[derive(Resource, Default)]
pub struct GlobalAnimationTimer(pub Timer);

pub fn update_frame_count(
time: Res<Time>,
mut global_animation_frame: ResMut<GlobalAnimationFrame>,
mut global_animation_timer: ResMut<GlobalAnimationTimer>,
) {
global_animation_timer.0.tick(time.delta());

if global_animation_timer.0.just_finished() {
    global_animation_frame.current_frame += 1;
}

}```

Then all my animations use the GlobalAnimationFrame and convert it to an index in a TextureAtlas.
Think this is similar to your problem.