bevy/examples/animation
poopy d9190e4ff6
Add Support for Triggering Events via AnimationEvents (#15538)
# Objective

Add support for events that can be triggered from animation clips. This
is useful when you need something to happen at a specific time in an
animation. For example, playing a sound every time a characters feet
hits the ground when walking.

Closes #15494 

## Solution

Added a new field to `AnimationClip`: `events`, which contains a list of
`AnimationEvent`s. These are automatically triggered in
`animate_targets` and `trigger_untargeted_animation_events`.

## Testing

Added a couple of tests and example (`animation_events.rs`) to make sure
events are triggered when expected.

---

## Showcase

`Events` need to also implement `AnimationEvent` and `Reflect` to be
used with animations.

```rust
#[derive(Event, AnimationEvent, Reflect)]
struct SomeEvent;
```

Events can be added to an `AnimationClip` by specifying a time and
event.

```rust
// trigger an event after 1.0 second
animation_clip.add_event(1.0, SomeEvent);
```

And optionally, providing a target id.

```rust
let id = AnimationTargetId::from_iter(["shoulder", "arm", "hand"]);
animation_clip.add_event_to_target(id, 1.0, HandEvent);
```

I modified the `animated_fox` example to show off the feature.

![CleanShot 2024-10-05 at 02 41
57](https://github.com/user-attachments/assets/0bb47db7-24f9-4504-88f1-40e375b89b1b)

---------

Co-authored-by: Matty <weatherleymatthew@gmail.com>
Co-authored-by: Chris Biscardi <chris@christopherbiscardi.com>
Co-authored-by: François Mockers <francois.mockers@vleue.com>
2024-10-06 10:03:05 +00:00
..
animated_fox.rs Add Support for Triggering Events via AnimationEvents (#15538) 2024-10-06 10:03:05 +00:00
animated_transform.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
animated_ui.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
animation_events.rs Add Support for Triggering Events via AnimationEvents (#15538) 2024-10-06 10:03:05 +00:00
animation_graph.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
animation_masks.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
color_animation.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
cubic_curve.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
custom_skinned_mesh.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
gltf_skinned_mesh.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00
morph_targets.rs Migrate cameras to required components (#15641) 2024-10-05 01:59:52 +00:00