Skip to content

Root motion implementation#24201

Open
Hilpogar wants to merge 26 commits into
bevyengine:mainfrom
Hilpogar:root-motion-part-3
Open

Root motion implementation#24201
Hilpogar wants to merge 26 commits into
bevyengine:mainfrom
Hilpogar:root-motion-part-3

Conversation

@Hilpogar
Copy link
Copy Markdown
Contributor

@Hilpogar Hilpogar commented May 8, 2026

Objective

Closes: #23355
Final step for the root motion implementation !

Solution

Add the RootMotion component that stores the informations about the root motion for the current frame:

pub struct RootMotion {
    /// Translation delta with the previous frame.
    pub translation_delta: Vec3,
    /// Rotation delta with the previous frame.
    pub rotation_delta: Quat,
}

Add the RootMotionMode to control how the RootMotion is extracted. There are 2 modes, one with only translation and one with translation and rotation :

pub enum RootMotionMode {
    /// Extract only translation from the root target.
    Translation,
    /// Extract both translation and rotation from the root target.
    #[default]
    TranslationAndRotation,
}

Add the field root_motion_target and root_motion_mode to the AnimationPlayer:

pub struct AnimationPlayer {
    <...>
    root_motion_target: Option<AnimationTargetId>,
    root_motion_mode: RootMotionMode,
}

Testing

The test_root_motion tests the extraction of the root motion in a configuration with 2 blended clips. The test is done once with the clips running forward and once backward.


Showcase

You can run the root_motion example to see it in action.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Animation Make things move and change over time M-Release-Note Work that should be called out in the blog due to impact labels May 8, 2026
@alice-i-cecile alice-i-cecile added this to the 0.20 milestone May 8, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Animation May 8, 2026
@alice-i-cecile alice-i-cecile added X-Contentious There are nontrivial implications that should be thought through S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels May 8, 2026
@Hilpogar Hilpogar force-pushed the root-motion-part-3 branch from 70ddfd8 to 8b7f259 Compare May 9, 2026 19:01
@Hilpogar Hilpogar marked this pull request as ready for review May 9, 2026 19:18
Comment thread examples/animation/root_motion.rs Outdated
Comment on lines +765 to +767
match self {
Self::Translation | Self::TranslationAndRotation => true,
}
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.

Seems like it would always be true here, maybe the match is not needed?

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.

Yes it's always true. I put the match in case we add more modes in the future so we don't forget to change here. I think it will be optimize by the compiler anyway. But I can replace it with just a true if you think it's not useful.

Comment thread crates/bevy_animation/src/lib.rs Outdated
Hilpogar and others added 4 commits May 10, 2026 07:30
Co-authored-by: François Mockers <francois.mockers@vleue.com>
Co-authored-by: François Mockers <francois.mockers@vleue.com>
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.

@Hilpogar
Copy link
Copy Markdown
Contributor Author

I realized that removing the AnimationPlayer from an entity could "leak" the RootMotion component. So I added a hook to remove it with the AnimationPlayer. I've also added the cleaning behaviors in the tests.

@Hilpogar Hilpogar requested review from mgi388 and mockersf May 11, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Animation Make things move and change over time C-Feature A new feature, making something new possible M-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged X-Contentious There are nontrivial implications that should be thought through

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Enable robust root motion for character animations

4 participants