Skip to content

Commit

Permalink
scene viewer improvements: animation reset (#4420)
Browse files Browse the repository at this point in the history
# 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~~
  • Loading branch information
mockersf committed Apr 7, 2022
1 parent f907d67 commit e7e7445
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion examples/tools/scene_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fn keyboard_animation_control(
mut animation_player: Query<&mut AnimationPlayer>,
scene_handle: Res<SceneHandle>,
mut current_animation: Local<usize>,
mut changing: Local<bool>,
) {
if scene_handle.animations.is_empty() {
return;
Expand All @@ -178,11 +179,20 @@ fn keyboard_animation_control(
}
}

if keyboard_input.just_pressed(KeyCode::Return) {
if *changing {
// change the animation the frame after return was pressed
*current_animation = (*current_animation + 1) % scene_handle.animations.len();
player
.play(scene_handle.animations[*current_animation].clone_weak())
.repeat();
*changing = false;
}

if keyboard_input.just_pressed(KeyCode::Return) {
// delay the animation change for one frame
*changing = true;
// set the current animation to its start and pause it to reset to its starting state
player.set_elapsed(0.0).pause();
}
}
}
Expand Down

0 comments on commit e7e7445

Please sign in to comment.