Skip to content

Commit c730d8c

Browse files
authored
Fix animations resetting after repeat count (#10540)
# 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.
1 parent 9f4c3e9 commit c730d8c

File tree

1 file changed

+9
-4
lines changed
  • crates/bevy_animation/src

1 file changed

+9
-4
lines changed

crates/bevy_animation/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,20 @@ impl PlayingAnimation {
190190
self.elapsed += delta;
191191
self.seek_time += delta * self.speed;
192192

193-
if (self.seek_time > clip_duration && self.speed > 0.0)
194-
|| (self.seek_time < 0.0 && self.speed < 0.0)
195-
{
193+
let over_time = self.speed > 0.0 && self.seek_time >= clip_duration;
194+
let under_time = self.speed < 0.0 && self.seek_time < 0.0;
195+
196+
if over_time || under_time {
196197
self.completions += 1;
197-
}
198198

199+
if self.is_finished() {
200+
return;
201+
}
202+
}
199203
if self.seek_time >= clip_duration {
200204
self.seek_time %= clip_duration;
201205
}
206+
// Note: assumes delta is never lower than -clip_duration
202207
if self.seek_time < 0.0 {
203208
self.seek_time += clip_duration;
204209
}

0 commit comments

Comments
 (0)