Skip to content

Commit de0994d

Browse files
Fix issue when adding colliders to an inactive body
1 parent 5807924 commit de0994d

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [0.10.2] - 2024-10-01
4+
5+
- Issue [#402](https://github.com/DanielChappuis/reactphysics3d/issues/402) Adding colliders to inactive body
6+
7+
### Fixed
8+
39
## [0.10.1] - 2024-06-25
410

511
### Fixed

src/body/Body.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,15 @@ Collider* Body::addCollider(CollisionShape* collisionShape, const Transform& tra
105105

106106
#endif
107107

108-
// Compute the world-space AABB of the new collision shape
109-
const AABB aabb = collisionShape->computeTransformedAABB(mWorld.mTransformComponents.getTransform(mEntity) * transform);
108+
// If the body is active
109+
if (isActive) {
110+
111+
// Compute the world-space AABB of the new collision shape
112+
const AABB aabb = collisionShape->computeTransformedAABB(mWorld.mTransformComponents.getTransform(mEntity) * transform);
110113

111-
// Notify the collision detection about this new collision shape
112-
mWorld.mCollisionDetection.addCollider(collider, aabb);
114+
// Notify the collision detection about this new collision shape
115+
mWorld.mCollisionDetection.addCollider(collider, aabb);
116+
}
113117

114118
RP3D_LOG(mWorld.mConfig.worldName, Logger::Level::Information, Logger::Category::Body,
115119
"Body " + std::to_string(mEntity.id) + ": Collider " + std::to_string(collider->getBroadPhaseId()) + " added to body", __FILE__, __LINE__);

src/body/RigidBody.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,16 @@ Collider* RigidBody::addCollider(CollisionShape* collisionShape, const Transform
696696

697697
#endif
698698

699-
// Compute the world-space AABB of the new collision shape
700-
AABB aabb = collisionShape->computeTransformedAABB(mWorld.mTransformComponents.getTransform(mEntity) * transform);
699+
// If the body is active
700+
const bool isActive = mWorld.mBodyComponents.getIsActive(mEntity);
701+
if (isActive) {
701702

702-
// Notify the collision detection about this new collision shape
703-
mWorld.mCollisionDetection.addCollider(collider, aabb);
703+
// Compute the world-space AABB of the new collision shape
704+
AABB aabb = collisionShape->computeTransformedAABB(mWorld.mTransformComponents.getTransform(mEntity) * transform);
705+
706+
// Notify the collision detection about this new collision shape
707+
mWorld.mCollisionDetection.addCollider(collider, aabb);
708+
}
704709

705710
RP3D_LOG(mWorld.mConfig.worldName, Logger::Level::Information, Logger::Category::Body,
706711
"Body " + std::to_string(mEntity.id) + ": Collider " + std::to_string(collider->getBroadPhaseId()) + " added to body", __FILE__, __LINE__);

0 commit comments

Comments
 (0)