Skip to content

Commit e7e7445

Browse files
committed
scene viewer improvements: animation reset (#4420)
# Objective - Changing animation mid animation can leave the model not in its original position - ~~The movement speed is fixed, no matter the size of the model~~ ## Solution - when changing animation, set it to its initial state and wait for one frame before changing the animation - ~~when settings the camera controller, use the camera transform to know how far it is from the origin and use the distance for the speed~~
1 parent f907d67 commit e7e7445

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

examples/tools/scene_viewer.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ fn keyboard_animation_control(
164164
mut animation_player: Query<&mut AnimationPlayer>,
165165
scene_handle: Res<SceneHandle>,
166166
mut current_animation: Local<usize>,
167+
mut changing: Local<bool>,
167168
) {
168169
if scene_handle.animations.is_empty() {
169170
return;
@@ -178,11 +179,20 @@ fn keyboard_animation_control(
178179
}
179180
}
180181

181-
if keyboard_input.just_pressed(KeyCode::Return) {
182+
if *changing {
183+
// change the animation the frame after return was pressed
182184
*current_animation = (*current_animation + 1) % scene_handle.animations.len();
183185
player
184186
.play(scene_handle.animations[*current_animation].clone_weak())
185187
.repeat();
188+
*changing = false;
189+
}
190+
191+
if keyboard_input.just_pressed(KeyCode::Return) {
192+
// delay the animation change for one frame
193+
*changing = true;
194+
// set the current animation to its start and pause it to reset to its starting state
195+
player.set_elapsed(0.0).pause();
186196
}
187197
}
188198
}

0 commit comments

Comments
 (0)