diff options
| author | Jan Hohenheim <jan@hohenheim.ch> | 2023-02-04 20:59:35 +0100 |
|---|---|---|
| committer | Jan Hohenheim <jan@hohenheim.ch> | 2023-02-04 20:59:35 +0100 |
| commit | 8d182cef7d30f1c81e447a475ab916137a567b4d (patch) | |
| tree | f2285ff4f1535bc4ba5a2921351de3d3dbdf23cb /src | |
| parent | f9a50856be6c4976c3a1379570bf46b01b421054 (diff) | |
| download | rapier-8d182cef7d30f1c81e447a475ab916137a567b4d.tar.gz rapier-8d182cef7d30f1c81e447a475ab916137a567b4d.tar.bz2 rapier-8d182cef7d30f1c81e447a475ab916137a567b4d.zip | |
Fix inconsistency in grounded detection at manifold
Diffstat (limited to 'src')
| -rw-r--r-- | src/control/character_controller.rs | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/control/character_controller.rs b/src/control/character_controller.rs index c258b7a..abccfee 100644 --- a/src/control/character_controller.rs +++ b/src/control/character_controller.rs @@ -403,22 +403,14 @@ impl KinematicCharacterController { .filter(|rb| rb.is_kinematic()); for m in &manifolds { - let normal = -(character_pos * m.local_n1); - if normal.dot(&self.up) >= 1.0e-5 { + if self.is_grounded_at_contact_manifold(m, character_pos, dims) { grounded = true; - println!("grounded!"); - println!("normal: {:?}", normal); - println!("up: {:?}", self.up); - println!("dot: {:?}", normal.dot(&self.up)); - println!("character_pos: {:?}", character_pos); - println!("m.local_n1: {:?}", m.local_n1); - println!("m.local_n2: {:?}", m.local_n2); - println!(); } if let Some(kinematic_parent) = kinematic_parent { let mut num_active_contacts = 0; let mut manifold_center = Point::origin(); + let normal = -(character_pos * m.local_n1); for contact in &m.points { if contact.dist <= prediction { @@ -458,15 +450,9 @@ impl KinematicCharacterController { *kinematic_friction_translation - init_kinematic_friction_translation; } else { for m in &manifolds { - let normal = character_pos * m.local_n1; - - if normal.dot(&self.up) <= 1.0e-5 { - for contact in &m.points { - if contact.dist <= prediction { - grounded = true; - return false; // We can stop the search early. - } - } + if self.is_grounded_at_contact_manifold(m, character_pos, dims) { + grounded = true; + return false; // We can stop the search early. } } } @@ -478,6 +464,25 @@ impl KinematicCharacterController { grounded } + fn is_grounded_at_contact_manifold( + &self, + manifold: &ContactManifold, + character_pos: &Isometry<Real>, + dims: &Vector2<Real>, + ) -> bool { + let normal = -(character_pos * manifold.local_n1); + + if normal.dot(&self.up) >= 1.0e-5 { + let prediction = self.predict_ground(dims.y); + for contact in &manifold.points { + if contact.dist <= prediction { + return true; + } + } + } + false + } + fn handle_slopes( &self, hit: &TOI, |
