Skip to content

Commit

Permalink
Fix colliders without RigidBody not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Jondolf committed Feb 12, 2024
1 parent adb3a19 commit 726320c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/plugins/collision/broad_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl MapEntities for AabbIntervals {
fn update_aabb_intervals(
aabbs: Query<(
&ColliderAabb,
&ColliderParent,
Option<&ColliderParent>,
Option<&CollisionLayers>,
Ref<Position>,
Ref<Rotation>,
Expand All @@ -199,10 +199,11 @@ fn update_aabb_intervals(
aabbs.get(*collider_entity)
{
*aabb = *new_aabb;
*collider_parent = *new_parent;
*collider_parent = new_parent.map_or(ColliderParent(*collider_entity), |p| *p);
*layers = new_layers.map_or(CollisionLayers::default(), |layers| *layers);

let is_static = rbs.get(new_parent.get()).is_ok_and(RigidBody::is_static);
let is_static =
new_parent.is_some_and(|p| rbs.get(p.get()).is_ok_and(RigidBody::is_static));
*is_inactive = is_static || (!position.is_changed() && !rotation.is_changed());

true
Expand All @@ -219,7 +220,7 @@ fn add_new_aabb_intervals(
aabbs: Query<
(
Entity,
&ColliderParent,
Option<&ColliderParent>,
&ColliderAabb,
Option<&RigidBody>,
Option<&CollisionLayers>,
Expand All @@ -231,7 +232,7 @@ fn add_new_aabb_intervals(
let aabbs = aabbs.iter().map(|(ent, parent, aabb, rb, layers)| {
(
ent,
*parent,
parent.map_or(ColliderParent(ent), |p| *p),
*aabb,
// Default to treating collider as immovable/static for filtering unnecessary collision checks
layers.map_or(CollisionLayers::default(), |layers| *layers),
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ fn transform_to_position(
&mut Position,
Option<&AccumulatedTranslation>,
&mut Rotation,
&PreviousRotation,
&CenterOfMass,
Option<&PreviousRotation>,
Option<&CenterOfMass>,
)>,
) {
for (
Expand All @@ -433,7 +433,12 @@ fn transform_to_position(
let previous_transform = previous_transform.compute_transform();
let pos = position.0
+ accumulated_translation.map_or(Vector::ZERO, |t| {
get_pos_translation(t, previous_rotation, &rotation, center_of_mass)
get_pos_translation(
t,
&previous_rotation.copied().unwrap_or_default(),
&rotation,
&center_of_mass.copied().unwrap_or_default(),
)
});

#[cfg(feature = "2d")]
Expand Down

0 comments on commit 726320c

Please sign in to comment.