diff --git a/src/controller/ground.rs b/src/controller/ground.rs index 25a23b3..ca8b252 100644 --- a/src/controller/ground.rs +++ b/src/controller/ground.rs @@ -91,7 +91,7 @@ impl Ground { let ground_entity = ctx.collider_parent(entity).unwrap_or(entity); let mass = if let Ok(mass) = masses.get(ground_entity) { - mass.0.clone() + (**mass).clone() } else { MassProperties::default() }; @@ -436,21 +436,21 @@ impl CastResult { impl CastResult { /// Use the first shape in the shape-cast as the cast result. - pub fn from_toi1(toi: Toi) -> Self { - Self { + pub fn from_toi1(toi: Toi) -> Option { + toi.details.map(|details| Self { toi: toi.toi, - normal: toi.normal1, - point: toi.witness1, - } + normal: details.normal1, + point: details.witness1, + }) } /// Use the second shape in the shape-cast as the cast result. - pub fn from_toi2(toi: Toi) -> Self { - Self { + pub fn from_toi2(toi: Toi) -> Option { + toi.details.map(|details| Self { toi: toi.toi, - normal: toi.normal2, - point: toi.witness2, - } + normal: details.normal2, + point: details.witness2, + }) } } @@ -658,16 +658,20 @@ impl<'c, 'f> GroundCastParams<'c, 'f> { self.direction, self.shape, self.max_toi, + true, self.filter, ) else { return None; }; - if toi.status == TOIStatus::Penetrating || toi.toi <= std::f32::EPSILON { + if toi.toi <= std::f32::EPSILON { return None; } let (entity, cast) = (entity, CastResult::from_toi1(toi)); + let Some(cast) = cast else { + return None; + }; gizmos.ray(self.position, self.direction * cast.toi, Color::BLUE); gizmos.sphere( diff --git a/src/controller/mod.rs b/src/controller/mod.rs index 4bb37f9..f96c7ed 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -153,7 +153,7 @@ pub fn accumulate_forces( }; let ground_mass = if let Ok(mass) = masses.get(ground.entity) { - mass.0.clone() + (**mass).clone() } else { MassProperties::default() }; diff --git a/src/controller/movement.rs b/src/controller/movement.rs index d3f6809..e380054 100644 --- a/src/controller/movement.rs +++ b/src/controller/movement.rs @@ -136,7 +136,7 @@ pub fn movement_force( .unwrap_or(&GlobalTransform::IDENTITY); let ground_mass = if let Ok(mass) = masses.get(ground.entity) { - mass.0.clone() + (**mass).clone() } else { MassProperties::default() }; diff --git a/src/rapier.rs b/src/rapier.rs index fd61ef1..4e84ba6 100644 --- a/src/rapier.rs +++ b/src/rapier.rs @@ -91,9 +91,9 @@ pub fn apply_ground_forces( /// Sync rapier masses over to our masses. pub fn get_mass_from_rapier(mut query: Query<(&mut ControllerMass, &ReadMassProperties)>) { for (mut mass, rapier_mass) in &mut query { - mass.mass = rapier_mass.0.mass; - mass.inertia = rapier_mass.0.principal_inertia; - mass.com = rapier_mass.0.local_center_of_mass; + mass.mass = rapier_mass.mass; + mass.inertia = rapier_mass.principal_inertia; + mass.com = rapier_mass.local_center_of_mass; } }