From f087a039fffa8ba8d396b631f51f0eea66e461c2 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Sun, 29 Oct 2023 22:24:26 +0200 Subject: [PATCH] Improve movement in examples (#210) # Objective Fixes #170. Currently, the movement in examples like `move_marbles` and `cubes` is frame rate dependent because they are running in `Update` but don't use delta time. `basic_dynamic_character` and `basic_kinematic_character` on the other hand run in the `PhysicsSchedule`, but this can cause issues with missed inputs as reported in #170. The character controllers are also perhaps too basic and don't reflect real usage well, and the movement code isn't great and it doesn't support WASD. ## Solution - Put all movement systems in `Update` and use delta time (alternatively, you could send input events in `Update` and have another system handle the movement in the `PhysicsSchedule`) - Refactor input handling to be cleaner and to support WASD as well as arrow keys - Refactor character controller examples with `CharacterControllerBundle` and configuration options - Fix some meshes not being rendered due to `clone_weak` --- crates/bevy_xpbd_2d/examples/chain_2d.rs | 4 +- crates/bevy_xpbd_2d/examples/many_shapes.rs | 22 ++- crates/bevy_xpbd_2d/examples/move_marbles.rs | 24 +-- .../examples/one_way_platform_2d.rs | 26 +-- .../examples/basic_dynamic_character.rs | 132 ++++++++++----- .../examples/basic_kinematic_character.rs | 151 +++++++++++++----- crates/bevy_xpbd_3d/examples/chain_3d.rs | 59 ++++--- crates/bevy_xpbd_3d/examples/cubes.rs | 41 +++-- .../examples/custom_constraint.rs | 4 +- .../examples/distance_joint_3d.rs | 4 +- .../bevy_xpbd_3d/examples/fixed_joint_3d.rs | 4 +- .../examples/prismatic_joint_3d.rs | 4 +- .../examples/revolute_joint_3d.rs | 4 +- 13 files changed, 322 insertions(+), 157 deletions(-) diff --git a/crates/bevy_xpbd_2d/examples/chain_2d.rs b/crates/bevy_xpbd_2d/examples/chain_2d.rs index 36983669..83608a28 100644 --- a/crates/bevy_xpbd_2d/examples/chain_2d.rs +++ b/crates/bevy_xpbd_2d/examples/chain_2d.rs @@ -43,7 +43,7 @@ fn setup( FollowMouse, MaterialMesh2dBundle { mesh: particle_mesh.clone(), - material: particle_material.clone_weak(), + material: particle_material.clone(), ..default() }, )) @@ -57,7 +57,7 @@ fn setup( MassPropertiesBundle::new_computed(&Collider::ball(particle_radius), 1.0), MaterialMesh2dBundle { mesh: particle_mesh.clone(), - material: particle_material.clone_weak(), + material: particle_material.clone(), transform: Transform::from_xyz( 0.0, i as f32 * (particle_radius as f32 * 2.0 + 1.0), diff --git a/crates/bevy_xpbd_2d/examples/many_shapes.rs b/crates/bevy_xpbd_2d/examples/many_shapes.rs index 14fe220a..c9b83ad3 100644 --- a/crates/bevy_xpbd_2d/examples/many_shapes.rs +++ b/crates/bevy_xpbd_2d/examples/many_shapes.rs @@ -136,21 +136,27 @@ fn setup( } fn movement( + time: Res