Skip to content

Commit

Permalink
Merge pull request #44 from Aceeri/bevy_rapier_update
Browse files Browse the repository at this point in the history
  • Loading branch information
Aceeri authored Oct 9, 2023
2 parents 61372f4 + f201ea8 commit 19c9c37
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
28 changes: 16 additions & 12 deletions src/controller/ground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down Expand Up @@ -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<Self> {
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<Self> {
toi.details.map(|details| Self {
toi: toi.toi,
normal: toi.normal2,
point: toi.witness2,
}
normal: details.normal2,
point: details.witness2,
})
}
}

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
2 changes: 1 addition & 1 deletion src/controller/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
6 changes: 3 additions & 3 deletions src/rapier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 19c9c37

Please sign in to comment.