Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f478556
change animation behavior for root bone
Hilpogar May 6, 2026
e23ec28
add a test for root motion
Hilpogar May 7, 2026
ff1e5dd
handle animation loops
Hilpogar May 7, 2026
bdb0238
check backward direction
Hilpogar May 7, 2026
a465895
add the RootMotion component
Hilpogar May 7, 2026
02bb39d
add rotation to tests
Hilpogar May 8, 2026
fe51b68
refactor tests
Hilpogar May 8, 2026
7b1c85c
tests work with blending
Hilpogar May 8, 2026
08f5d85
create fetch_curve_evaluator method
Hilpogar May 8, 2026
22171af
documentation
Hilpogar May 8, 2026
811ff37
don't extract rotation if not configured
Hilpogar May 9, 2026
2010ea2
change test values to have bigger potential errors
Hilpogar May 9, 2026
502f317
add a system to remove RootMotion when it's disabled
Hilpogar May 9, 2026
b977aa1
add root motion example
Hilpogar May 9, 2026
7fcad9c
add release note
Hilpogar May 9, 2026
23b2fe6
missed formatting
Hilpogar May 9, 2026
74a855a
clippy
Hilpogar May 9, 2026
8b7f259
ci errors
Hilpogar May 9, 2026
bb3fd87
fix description causing issues
Hilpogar May 9, 2026
7ff8e63
add PartialEq to RootMotionMode
Hilpogar May 9, 2026
0f122e2
Update examples/animation/root_motion.rs
Hilpogar May 10, 2026
5cd174e
Update crates/bevy_animation/src/lib.rs
Hilpogar May 10, 2026
a1e95e7
fix suggestion
Hilpogar May 10, 2026
9931310
clean RootMotion when AnimationPlayer is removed
Hilpogar May 10, 2026
65cbf7d
test if RootMotion is removed with AnimationPlayer
Hilpogar May 11, 2026
cb434d9
check if disabling root_motion_target removes RootMotion the next frame
Hilpogar May 11, 2026
7c289a9
apply root motion after animation systems
Hilpogar May 20, 2026
c6074c8
add track_caller to test helper functions
Hilpogar May 20, 2026
24ab2cc
add Clone and PartialEq to RootMotion
Hilpogar May 26, 2026
0430376
move find_root_bone_recursive in bevy_animation
Hilpogar May 26, 2026
dc9eded
move root motion config from AnimationPlayer to RootMotionConfig
Hilpogar May 26, 2026
b6e8ed5
document RootMotionMode match
Hilpogar May 26, 2026
70437d0
document FoxRootMotion.glb
Hilpogar May 26, 2026
a4163d5
add a migration guide for AnimationCurveEvaluator
Hilpogar May 26, 2026
2d79ad2
fix ci import issue
Hilpogar May 26, 2026
6775369
change animated_field! to remove the need to import AnimatedField
Hilpogar May 27, 2026
9c7b15b
Merge branch 'main' into root-motion-part-3
Hilpogar May 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,21 @@ description = "Plays an animation from a glTF file with meshes with morph target
category = "Animation"
wasm = true

[[example]]
name = "root_motion"
path = "examples/animation/root_motion.rs"
doc-scrape-examples = true

[package.metadata.example.root_motion]
name = "Root Motion"
description = """
Plays an animation and use root motion to move the entity.

When root motion is disabled only the mesh is moved so the position resets each time the animation resets.
When root motion is enabled, the mesh stays in place and the movement is transferred to the main entity."""
category = "Animation"
wasm = true

[[example]]
name = "animated_transform"
path = "examples/animation/animated_transform.rs"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Change function signature of commit in AnimationCurveEvaluator
pull_requests: [24201]
---

The root motion feature needs to access the animated entity after the curves are applied. For this reason, the commit method of
AnimationCurveEvaluator changed from :

```rust
fn commit(&mut self, entity: AnimationEntityMut) -> Result<(), AnimationEvaluationError>;
```

to

```rust
fn commit(&mut self, entity: &mut AnimationEntityMut) -> Result<(), AnimationEvaluationError>;
```

Passing the AnimationEntityMut by mutable reference is now necessary.
12 changes: 12 additions & 0 deletions _release-content/release-notes/root_motion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Root Motion
authors: ["@Hilpogar", "@emberlightstudios"]
pull_requests: [24201]
---

In animation and game development, root motion is a technique where the movement of a character is driven directly by the animation’s root bone instead of being controlled purely by code or physics.
It is used to create more natural, accurate movements such as walking, climbing, or attacks, by synchronizing the character’s in-game position with the animation itself.

You can now use this technique by using the `set_root_motion_target` method in the `AnimationPlayer`. To do so, you need to get the `AnimationTargetId` of your model's root motion bone.
It can be the root bone or any bone you want. When a bone is configured to be used for root motion, its position and / or rotation will be erased each frame and the delta with the previous
frame is stored in the `RootMotion` component inside the `AnimationPlayer`'s entity. You can configure if the root motion should extract translation and rotation or just translation with the `set_root_motion_mode` method in `AnimationPlayer`.
Binary file added assets/models/animated/FoxRootMotion.glb

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for someone to check if this asset is allowed to be committed or if it needs to be a remote/web asset.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because of potential copyright or licensing issues with the model, or is it just to avoid overloading the repository? If it’s a licensing issue, please note that this is simply the existing fox model to which I’ve added root motion to the running animation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s to do with repo size / bloat. E.g., see #23567 (comment)

I don’t know the bytes threshold but AFAIK, I think bevy wants to avoid putting more assets in this repo if possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a comment indicating what the changes to the file are here. Notably in case it ever needs to be modified or understood in the future. Otherwise it will be hard for future contributors to comprehend why this is a separate file.

Personally I think a FoxRootMotion.md that explains the steps taken to create the new file from the original would work.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that. This is not so big that I think we have to move it out though IMO, but clear guidance here would have been nice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a ForRootMotion.md containing the instructions to recreate the file. This is a very slight modification of the file, do you think the instructions are clear enough?

Binary file not shown.
4 changes: 4 additions & 0 deletions assets/models/animated/FoxRootMotion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# What's FoxRootMotion.glb

This model is the same as Fox.glb but with an additional curve for translation in the `b_Root_00` bone of the `run` animation.
It's used to illustrate the root motion in the root_motion example.
18 changes: 15 additions & 3 deletions crates/bevy_animation/src/animation_curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ pub struct AnimatableCurveEvaluator<A: Animatable> {
property: Box<dyn AnimatableProperty<Property = A>>,
}

impl<A: Animatable> AnimatableCurveEvaluator<A> {
pub(super) fn push_value(&mut self, value: A, weight: f32, graph_node: AnimationNodeIndex) {
self.evaluator
.stack
.push(BasicAnimationCurveEvaluatorStackElement {
value,
weight,
graph_node,
});
}
}

impl<P, C> AnimatableCurve<P, C>
where
P: AnimatableProperty,
Expand Down Expand Up @@ -413,8 +425,8 @@ impl<A: Animatable> AnimationCurveEvaluator for AnimatableCurveEvaluator<A> {
self.evaluator.push_blend_register(weight, graph_node)
}

fn commit(&mut self, mut entity: AnimationEntityMut) -> Result<(), AnimationEvaluationError> {
let property = self.property.get_mut(&mut entity)?;
fn commit(&mut self, entity: &mut AnimationEntityMut) -> Result<(), AnimationEvaluationError> {
Comment thread
alice-i-cecile marked this conversation as resolved.
let property = self.property.get_mut(entity)?;
*property = self
.evaluator
.stack
Expand Down Expand Up @@ -708,7 +720,7 @@ pub trait AnimationCurveEvaluator: Downcast + Send + Sync + 'static {
///
/// The property on the component must be overwritten with the value from
/// the stack, not blended with it.
fn commit(&mut self, entity: AnimationEntityMut) -> Result<(), AnimationEvaluationError>;
fn commit(&mut self, entity: &mut AnimationEntityMut) -> Result<(), AnimationEvaluationError>;
}

impl_downcast!(AnimationCurveEvaluator);
Expand Down
Loading
Loading