Skip to content

Commit

Permalink
Color visualization for grounded character controller (#705)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrixyz authored Aug 2, 2024
1 parent 595b952 commit 364b5b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples2d/character_controller2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn init_world(testbed: &mut Testbed) {
let character_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::capsule_y(0.3, 0.15);
colliders.insert_with_parent(collider, character_handle, &mut bodies);
testbed.set_initial_body_color(character_handle, [0.8, 0.1, 0.1]);

/*
* Create the cubes
Expand Down
1 change: 1 addition & 0 deletions examples3d/character_controller3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub fn init_world(testbed: &mut Testbed) {
let character_handle = bodies.insert(rigid_body);
let collider = ColliderBuilder::capsule_y(0.3 * scale, 0.15 * scale); // 0.15, 0.3, 0.15);
colliders.insert_with_parent(collider, character_handle, &mut bodies);
testbed.set_initial_body_color(character_handle, [0.8, 0.1, 0.1]);

/*
* Create the cubes
Expand Down
15 changes: 15 additions & 0 deletions src_testbed/testbed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,21 @@ 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),
);
if let Some(graphics) = &mut self.graphics {
if mvt.grounded {
graphics.graphics.set_body_color(
graphics.materials,
character_handle,
[0.1, 0.8, 0.1],
);
} else {
graphics.graphics.set_body_color(
graphics.materials,
character_handle,
[0.8, 0.1, 0.1],
);
}
}
controller.solve_character_collision_impulses(
phx.integration_parameters.dt,
&mut phx.bodies,
Expand Down

0 comments on commit 364b5b7

Please sign in to comment.