Skip to content

feat(animation): implement Animatable for Rot2#23621

Open
YurikoDX wants to merge 1 commit intobevyengine:mainfrom
YurikoDX:rot2-animation-main
Open

feat(animation): implement Animatable for Rot2#23621
YurikoDX wants to merge 1 commit intobevyengine:mainfrom
YurikoDX:rot2-animation-main

Conversation

@YurikoDX
Copy link
Copy Markdown

@YurikoDX YurikoDX commented Apr 2, 2026

Objective

This PR adds animation support for 2D rotations by implementing the Animatable trait for Rot2. This enables developers to smoothly animate 2D entities and UI elements.

(Note: This is a clean, cherry-picked recreation of #23618 targeting the main branch, as suggested by @alice-i-cecile .)

Solution

To ensure mathematical correctness and consistency with existing Bevy math types (like Quat), this implementation includes:

  • Shortest-path interpolation: Uses spherical linear interpolation (slerp) so that rotations naturally take the shortest route (e.g., passing through 0° rather than 180° when moving from 89° to -89°).
  • Standardized blending: Implements precise cumulative and additive blending logic that perfectly mirrors the behavior of Quat.
  • Comprehensive Unit Tests: Added tests specifically to verify:
    • Shortest path interpolation.
    • Absolute blending with equal weights.
    • Cumulative multi-way blending.
    • Additive blending.
  • Example Update: Updated the animated_ui example to showcase the new Rot2 animation capabilities.

Testing

  • All new unit tests pass (cargo test -p bevy_animation --lib animatable).
  • Ran cargo fmt and cargo clippy.
  • Tested the animated_ui example locally to ensure the 2D rotation curve behaves as expected.

@alice-i-cecile
Copy link
Copy Markdown
Member

Clippy is failing :)

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Animation Make things move and change over time D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 2, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Animation Apr 2, 2026
Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

LGTM other than clippy now. Thanks for cleaning this up :)

This adds animation support for 2D rotations by implementing the `Animatable` trait for `Rot2`.

- Uses spherical linear interpolation (slerp) to ensure shortest-path consistency.
- Implements correct cumulative and additive blending logic matching existing mathematical types like `Quat`.
- Adds unit tests verifying shortest-path behavior and cumulative weighting.
- Updates the `animated_ui` example to showcase `Rot2` rotation animation.
@YurikoDX YurikoDX force-pushed the rot2-animation-main branch from 8eb8ed9 to ea53e5f Compare April 2, 2026 05:00
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-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants