diff options
Diffstat (limited to 'src/geometry')
| -rw-r--r-- | src/geometry/collider.rs | 1 | ||||
| -rw-r--r-- | src/geometry/collider_set.rs | 16 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/geometry/collider.rs b/src/geometry/collider.rs index 612df3c..b9007bf 100644 --- a/src/geometry/collider.rs +++ b/src/geometry/collider.rs @@ -33,7 +33,6 @@ pub struct Collider { impl Collider { pub(crate) fn reset_internal_references(&mut self) { - self.co_parent = None; self.co_bf_data.proxy_index = crate::INVALID_U32; self.co_changes = ColliderChanges::all(); } diff --git a/src/geometry/collider_set.rs b/src/geometry/collider_set.rs index d8603cd..dc0abdc 100644 --- a/src/geometry/collider_set.rs +++ b/src/geometry/collider_set.rs @@ -134,6 +134,7 @@ impl ColliderSet { // Make sure the internal links are reset, they may not be // if this rigid-body was obtained by cloning another one. coll.reset_internal_references(); + coll.co_parent = None; let handle = ColliderHandle(self.colliders.insert(coll)); self.modified_colliders.push(handle); handle @@ -147,12 +148,17 @@ impl ColliderSet { bodies: &mut RigidBodySet, ) -> ColliderHandle { // Make sure the internal links are reset, they may not be - // if this rigid-body was obtained by cloning another one. + // if this collider was obtained by cloning another one. coll.reset_internal_references(); - coll.co_parent = Some(ColliderParent { - handle: parent_handle, - pos_wrt_parent: coll.co_pos.0, - }); + + if let Some(prev_parent) = &mut coll.co_parent { + prev_parent.handle = parent_handle; + } else { + coll.co_parent = Some(ColliderParent { + handle: parent_handle, + pos_wrt_parent: coll.co_pos.0, + }); + } // NOTE: we use `get_mut` instead of `get_mut_internal` so that the // modification flag is updated properly. |
