Skip to content

Commit

Permalink
Fix issue when adding colliders to an inactive body
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielChappuis committed Sep 16, 2024
1 parent 5807924 commit de0994d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/body/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down
13 changes: 9 additions & 4 deletions src/body/RigidBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down

0 comments on commit de0994d

Please sign in to comment.