Fix CharacterController max/min slope handling (#701)
This commit is contained in:
@@ -102,6 +102,7 @@ pub struct TestbedState {
|
||||
pub draw_colls: bool,
|
||||
pub highlighted_body: Option<RigidBodyHandle>,
|
||||
pub character_body: Option<RigidBodyHandle>,
|
||||
pub character_controller: Option<KinematicCharacterController>,
|
||||
#[cfg(feature = "dim3")]
|
||||
pub vehicle_controller: Option<DynamicRayCastVehicleController>,
|
||||
// pub grabbed_object: Option<DefaultBodyPartHandle>,
|
||||
@@ -186,6 +187,7 @@ impl TestbedApp {
|
||||
draw_colls: false,
|
||||
highlighted_body: None,
|
||||
character_body: None,
|
||||
character_controller: None,
|
||||
#[cfg(feature = "dim3")]
|
||||
vehicle_controller: None,
|
||||
// grabbed_object: None,
|
||||
@@ -530,6 +532,10 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> Testbed<'a, 'b, 'c, 'd, 'e, 'f> {
|
||||
self.state.character_body = Some(handle);
|
||||
}
|
||||
|
||||
pub fn set_character_controller(&mut self, controller: Option<KinematicCharacterController>) {
|
||||
self.state.character_controller = controller;
|
||||
}
|
||||
|
||||
#[cfg(feature = "dim3")]
|
||||
pub fn set_vehicle_controller(&mut self, controller: DynamicRayCastVehicleController) {
|
||||
self.state.vehicle_controller = Some(controller);
|
||||
@@ -827,7 +833,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f> Testbed<'a, 'b, 'c, 'd, 'e, 'f> {
|
||||
desired_movement *= speed;
|
||||
desired_movement -= Vector::y() * speed;
|
||||
|
||||
let controller = KinematicCharacterController::default();
|
||||
let controller = self.state.character_controller.unwrap_or_default();
|
||||
let phx = &mut self.harness.physics;
|
||||
let character_body = &phx.bodies[character_handle];
|
||||
let character_collider = &phx.colliders[character_body.colliders()[0]];
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use rapier::control::CharacterLength;
|
||||
use rapier::counters::Counters;
|
||||
use rapier::math::Real;
|
||||
use std::num::NonZeroUsize;
|
||||
@@ -240,7 +241,40 @@ pub fn update_ui(
|
||||
// .set(TestbedStateFlags::CONTACT_POINTS, contact_points);
|
||||
// state.flags.set(TestbedStateFlags::WIREFRAME, wireframe);
|
||||
ui.separator();
|
||||
if let Some(character_controller) = &mut state.character_controller {
|
||||
ui.label("Character controller");
|
||||
ui.checkbox(&mut character_controller.slide, "slide").on_hover_text("Should the character try to slide against the floor if it hits it?");
|
||||
#[allow(clippy::useless_conversion)]
|
||||
{
|
||||
|
||||
ui.add(Slider::new(&mut character_controller.max_slope_climb_angle, 0.0..=std::f32::consts::TAU.into()).text("max_slope_climb_angle"))
|
||||
.on_hover_text("The maximum angle (radians) between the floor’s normal and the `up` vector that the character is able to climb.");
|
||||
ui.add(Slider::new(&mut character_controller.min_slope_slide_angle, 0.0..=std::f32::consts::FRAC_PI_2.into()).text("min_slope_slide_angle"))
|
||||
.on_hover_text("The minimum angle (radians) between the floor’s normal and the `up` vector before the character starts to slide down automatically.");
|
||||
}
|
||||
let mut is_snapped = character_controller.snap_to_ground.is_some();
|
||||
if ui.checkbox(&mut is_snapped, "snap_to_ground").changed {
|
||||
match is_snapped {
|
||||
true => {
|
||||
character_controller.snap_to_ground = Some(CharacterLength::Relative(0.1));
|
||||
},
|
||||
false => {
|
||||
character_controller.snap_to_ground = None;
|
||||
},
|
||||
}
|
||||
}
|
||||
if let Some(snapped) = &mut character_controller.snap_to_ground {
|
||||
match snapped {
|
||||
CharacterLength::Relative(val) => {
|
||||
ui.add(Slider::new(val, 0.0..=10.0).text("Snapped Relative Character Length"));
|
||||
},
|
||||
CharacterLength::Absolute(val) => {
|
||||
ui.add(Slider::new(val, 0.0..=10.0).text("Snapped Absolute Character Length"));
|
||||
},
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
}
|
||||
let label = if state.running == RunMode::Stop {
|
||||
"Start (T)"
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user