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~~
This commit is contained in:
parent
f907d67d7e
commit
e7e74457c7
@ -164,6 +164,7 @@ fn keyboard_animation_control(
|
|||||||
mut animation_player: Query<&mut AnimationPlayer>,
|
mut animation_player: Query<&mut AnimationPlayer>,
|
||||||
scene_handle: Res<SceneHandle>,
|
scene_handle: Res<SceneHandle>,
|
||||||
mut current_animation: Local<usize>,
|
mut current_animation: Local<usize>,
|
||||||
|
mut changing: Local<bool>,
|
||||||
) {
|
) {
|
||||||
if scene_handle.animations.is_empty() {
|
if scene_handle.animations.is_empty() {
|
||||||
return;
|
return;
|
||||||
@ -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();
|
*current_animation = (*current_animation + 1) % scene_handle.animations.len();
|
||||||
player
|
player
|
||||||
.play(scene_handle.animations[*current_animation].clone_weak())
|
.play(scene_handle.animations[*current_animation].clone_weak())
|
||||||
.repeat();
|
.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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user