diff --git a/src/body/CollisionBody.cpp b/src/body/CollisionBody.cpp index 05c03e4b..9c2cd841 100644 --- a/src/body/CollisionBody.cpp +++ b/src/body/CollisionBody.cpp @@ -287,14 +287,15 @@ bool CollisionBody::testPointInside(const Vector3& worldPoint) const { /// The method returns the closest hit among all the collision shapes of the body bool CollisionBody::raycast(const Ray& ray, RaycastInfo& raycastInfo) { + // If the body is not active, it cannot be hit by rays + if (!mIsActive) return false; + bool isHit = false; Ray rayTemp(ray); // For each collision shape of the body for (ProxyShape* shape = mProxyCollisionShapes; shape != NULL; shape = shape->mNext) { - // TODO : Test for broad-phase hit for each shape before testing actual shape raycast - // Test if the ray hits the collision shape if (shape->raycast(rayTemp, raycastInfo)) { rayTemp.maxFraction = raycastInfo.hitFraction; diff --git a/src/collision/ProxyShape.h b/src/collision/ProxyShape.h index 8493b0d1..fa38a68c 100644 --- a/src/collision/ProxyShape.h +++ b/src/collision/ProxyShape.h @@ -167,6 +167,10 @@ inline decimal ProxyShape::getMargin() const { // Raycast method with feedback information inline bool ProxyShape::raycast(const Ray& ray, RaycastInfo& raycastInfo) { + + // If the corresponding body is not active, it cannot be hit by rays + if (!mBody->isActive()) return false; + return mCollisionShape->raycast(ray, raycastInfo, this); }