Skip to content

Commit

Permalink
feat: change the character controller’s solve_character_collision_imp…
Browse files Browse the repository at this point in the history
…ulses to take multiple CharacterCollision (#646)

* character controller: solve multiple collisions

* add solve multiple collisions to changelog

* chore: apply review comments

---------

Co-authored-by: Sébastien Crozet <[email protected]>
  • Loading branch information
Vrixyz and sebcrozet authored Jun 9, 2024
1 parent a8a0f29 commit 8160b4e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ This release introduces two new crates:
- Rename `JointAxesMask::X/Y/Z` to `::LIN_X/LIN_Y/LIN_Z` to avoid confusing it with `::ANG_X/ANG_Y/ANG_Z`.
- The function `RigidBody::add_collider` is now private. It was only public because it was needed for some internal
`bevy_rapier` plumbings, but it is no longer useful. Adding a collider must always go througthe `ColliderSet`.
- `CharacterController::solve_character_collision_impulses` now takes multiple `CharacterCollision` as parameter:
this change will allow further internal optimizations.

## v0.19.0 (05 May 2024)

Expand Down
33 changes: 31 additions & 2 deletions src/control/character_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,40 @@ impl KinematicCharacterController {
true
}

/// For a given collision between a character and its environment, this method will apply
/// impulses to the rigid-bodies surrounding the character shape at the time of the collision.
/// For the given collisions between a character and its environment, this method will apply
/// impulses to the rigid-bodies surrounding the character shape at the time of the collisions.
/// Note that the impulse calculation is only approximate as it is not based on a global
/// constraints resolution scheme.
pub fn solve_character_collision_impulses(
&self,
dt: Real,
bodies: &mut RigidBodySet,
colliders: &ColliderSet,
queries: &QueryPipeline,
character_shape: &dyn Shape,
character_mass: Real,
collisions: impl IntoIterator<Item = CharacterCollision>,
filter: QueryFilter,
) {
for collision in collisions {
self.solve_single_character_collision_impulse(
dt,
bodies,
colliders,
queries,
character_shape,
character_mass,
&collision,
filter,
);
}
}

/// For the given collision between a character and its environment, this method will apply
/// impulses to the rigid-bodies surrounding the character shape at the time of the collision.
/// Note that the impulse calculation is only approximate as it is not based on a global
/// constraints resolution scheme.
fn solve_single_character_collision_impulse(
&self,
dt: Real,
bodies: &mut RigidBodySet,
Expand Down
23 changes: 10 additions & 13 deletions src_testbed/testbed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,19 +811,16 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> Testbed<'a, 'b, 'c, 'd, 'e, 'f> {
QueryFilter::new().exclude_rigid_body(character_handle),
|c| collisions.push(c),
);

for collision in &collisions {
controller.solve_character_collision_impulses(
phx.integration_parameters.dt,
&mut phx.bodies,
&phx.colliders,
&phx.query_pipeline,
character_collider.shape(),
character_mass,
collision,
QueryFilter::new().exclude_rigid_body(character_handle),
)
}
controller.solve_character_collision_impulses(
phx.integration_parameters.dt,
&mut phx.bodies,
&phx.colliders,
&phx.query_pipeline,
character_collider.shape(),
character_mass,
collisions,
QueryFilter::new().exclude_rigid_body(character_handle),
);

let character_body = &mut phx.bodies[character_handle];
let pos = character_body.position();
Expand Down

0 comments on commit 8160b4e

Please sign in to comment.