diff options
Diffstat (limited to 'src/content/entities')
| -rw-r--r-- | src/content/entities/entity_wizard.rs | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/content/entities/entity_wizard.rs b/src/content/entities/entity_wizard.rs index 6707f7c..3787e49 100644 --- a/src/content/entities/entity_wizard.rs +++ b/src/content/entities/entity_wizard.rs @@ -9,6 +9,7 @@ use crate::{ input::Input, sim::{ entity::{EntityBehaviour, EntityDef, EntityUpdateCtx}, + rb_manager::character_impulses::solve_character_collision_impulses, sim_manager::SimCtx, }, }; @@ -37,7 +38,7 @@ impl EntityBehaviour for WizardEntityBehaviour { self.movement_input_x = 0.0; } - if ctx.input_manager.pressed(Input::Up) { + if ctx.input_manager.pressed(Input::Jump) { self.jump = 0.06; } } @@ -87,7 +88,15 @@ impl EntityBehaviour for WizardEntityBehaviour { .rb_manager .physics_manager .world - .query_pipeline_with_filter( + .broad_phase + .as_query_pipeline( + ctx.rb_manager + .physics_manager + .world + .narrow_phase + .query_dispatcher(), + &ctx.rb_manager.physics_manager.world.bodies, + &ctx.rb_manager.physics_manager.world.colliders, QueryFilter::default().exclude_rigid_body(update_ctx.entity_data.rb_h.unwrap()), ); @@ -105,19 +114,49 @@ impl EntityBehaviour for WizardEntityBehaviour { .world .colliders .get(update_ctx.entity_data.collider_h.unwrap()) - .unwrap(); + .unwrap() + .clone(); // move_shape works in translations, not velocities: feed it the distance we // want to cover this step, and convert the allowed distance back to a velocity. + let mut collisions = Vec::new(); let movement = self.kinematic_controller.move_shape( delta_time, &query_pipeline, collider.shape(), rb.position(), self.acc_vel * delta_time, - |_| {}, + |col| collisions.push(col), + ); + + let mut query_pipeline_mut = ctx + .rb_manager + .physics_manager + .world + .broad_phase + .as_query_pipeline_mut( + ctx.rb_manager + .physics_manager + .world + .narrow_phase + .query_dispatcher(), + &mut ctx.rb_manager.physics_manager.world.bodies, + &mut ctx.rb_manager.physics_manager.world.colliders, + QueryFilter::default().exclude_rigid_body(update_ctx.entity_data.rb_h.unwrap()), + ); + + // apply collisions to other scene entities. Local port: rapier's own + // solve_character_collision_impulses panics with 2+ nearby dynamic bodies. + solve_character_collision_impulses( + &self.kinematic_controller, + delta_time, + &mut query_pipeline_mut, + collider.shape(), + update_ctx.entity_data.cells.as_mut().unwrap().mass(), + &collisions, ); + // update the entity's position let rb = ctx .rb_manager .physics_manager |
