Skip to content

Commit

Permalink
Fix animations resetting after repeat count (#10540)
Browse files Browse the repository at this point in the history
# Objective

After #9002, it seems that "single shot" animations were broken. When
completing, they would reset to their initial value. Which is generally
not what you want.

- Fixes #10480

## Solution

Avoid `%`-ing the animation after the number of completions exceeds the
specified one. Instead, we early-return. This is also true when the
player is playing in reverse.

---

## Changelog

- Avoid resetting animations after `Repeat::Never` animation completion.
  • Loading branch information
nicopap authored Nov 14, 2023
1 parent 9f4c3e9 commit c730d8c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,20 @@ impl PlayingAnimation {
self.elapsed += delta;
self.seek_time += delta * self.speed;

if (self.seek_time > clip_duration && self.speed > 0.0)
|| (self.seek_time < 0.0 && self.speed < 0.0)
{
let over_time = self.speed > 0.0 && self.seek_time >= clip_duration;
let under_time = self.speed < 0.0 && self.seek_time < 0.0;

if over_time || under_time {
self.completions += 1;
}

if self.is_finished() {
return;
}
}
if self.seek_time >= clip_duration {
self.seek_time %= clip_duration;
}
// Note: assumes delta is never lower than -clip_duration
if self.seek_time < 0.0 {
self.seek_time += clip_duration;
}
Expand Down

0 comments on commit c730d8c

Please sign in to comment.