Allow removing a rigid-body without auto-removing attached colliders

This commit is contained in:
Sébastien Crozet
2022-02-20 14:21:59 +01:00
committed by Sébastien Crozet
parent 412fedf7e3
commit 28cc19d104
7 changed files with 327 additions and 236 deletions

View File

@@ -141,6 +141,7 @@ impl RigidBodySet {
colliders: &mut ColliderSet,
impulse_joints: &mut ImpulseJointSet,
multibody_joints: &mut MultibodyJointSet,
remove_attached_colliders: bool,
) -> Option<RigidBody> {
let rb = self.bodies.remove(handle.0)?;
/*
@@ -151,8 +152,16 @@ impl RigidBodySet {
/*
* Remove colliders attached to this rigid-body.
*/
for collider in rb.colliders() {
colliders.remove(*collider, islands, self, false);
if remove_attached_colliders {
for collider in rb.colliders() {
colliders.remove(*collider, islands, self, false);
}
} else {
// If we dont remove the attached colliders, simply detach them.
let colliders_to_detach = rb.colliders().to_vec();
for co_handle in colliders_to_detach {
colliders.set_parent(co_handle, None, self);
}
}
/*