diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a955c84..b23a8d5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.10.2] - 2024-10-01 + +- Issue [#402](https://github.com/DanielChappuis/reactphysics3d/issues/402) Adding colliders to inactive body + +### Fixed + ## [0.10.1] - 2024-06-25 ### Fixed diff --git a/src/body/Body.cpp b/src/body/Body.cpp index 891ec317..cf345228 100644 --- a/src/body/Body.cpp +++ b/src/body/Body.cpp @@ -105,11 +105,15 @@ Collider* Body::addCollider(CollisionShape* collisionShape, const Transform& tra #endif - // Compute the world-space AABB of the new collision shape - const AABB aabb = collisionShape->computeTransformedAABB(mWorld.mTransformComponents.getTransform(mEntity) * transform); + // If the body is active + if (isActive) { + + // Compute the world-space AABB of the new collision shape + const AABB aabb = collisionShape->computeTransformedAABB(mWorld.mTransformComponents.getTransform(mEntity) * transform); - // Notify the collision detection about this new collision shape - mWorld.mCollisionDetection.addCollider(collider, aabb); + // Notify the collision detection about this new collision shape + mWorld.mCollisionDetection.addCollider(collider, aabb); + } RP3D_LOG(mWorld.mConfig.worldName, Logger::Level::Information, Logger::Category::Body, "Body " + std::to_string(mEntity.id) + ": Collider " + std::to_string(collider->getBroadPhaseId()) + " added to body", __FILE__, __LINE__); diff --git a/src/body/RigidBody.cpp b/src/body/RigidBody.cpp index da162707..c2a5e119 100644 --- a/src/body/RigidBody.cpp +++ b/src/body/RigidBody.cpp @@ -696,11 +696,16 @@ Collider* RigidBody::addCollider(CollisionShape* collisionShape, const Transform #endif - // Compute the world-space AABB of the new collision shape - AABB aabb = collisionShape->computeTransformedAABB(mWorld.mTransformComponents.getTransform(mEntity) * transform); + // If the body is active + const bool isActive = mWorld.mBodyComponents.getIsActive(mEntity); + if (isActive) { - // Notify the collision detection about this new collision shape - mWorld.mCollisionDetection.addCollider(collider, aabb); + // Compute the world-space AABB of the new collision shape + AABB aabb = collisionShape->computeTransformedAABB(mWorld.mTransformComponents.getTransform(mEntity) * transform); + + // Notify the collision detection about this new collision shape + mWorld.mCollisionDetection.addCollider(collider, aabb); + } RP3D_LOG(mWorld.mConfig.worldName, Logger::Level::Information, Logger::Category::Body, "Body " + std::to_string(mEntity.id) + ": Collider " + std::to_string(collider->getBroadPhaseId()) + " added to body", __FILE__, __LINE__);