Possible Bug With Raycast

b b
Posts: 1
Joined: Wed Feb 09, 2011 11:33 pm

Possible Bug With Raycast

Post by b b »

I have found a repeatable instance where a raycast will not report a valid collision to the user (version 2.76).

I perform a raycast from {0,-9.5,0} to {0,-10,0} and have a static collision box(one of its sides on the y-plane) located at {0,-10,0}. The raycast returns 0 hits in the callback. The next frame passes and another raycast is called from {0,-10,0} to {0,-10.5,0}. Again the raycast returns 0 hits in the callback. If I perform the I perform a raycast from {0,-9.6,0} to {0,-10.1,0}, then the raycast returns a valid hit.

I found where the code was rejecting the first raycast's valid hit result.

File: BtCollisonWorld.cpp
Function: btCollisionWorld::rayTestSingle()
Line: 280.

Code: Select all

if (castResult.m_fraction < resultCallback.m_closestHitFraction)
The raycast fails because even though btSubsimplexConvexCast::calcTimeOfImpact() reports a valid hit, the castResult.m_fraction = 1.0 and resultCallback.m_closestHitFraction = 1.0 as well, which causes the conditional to be false.

When I changed the code to

Code: Select all

if (castResult.m_fraction <= resultCallback.m_closestHitFraction)

It works without any apparent problems.

I wanted to make sure that I'm not doing anything “dodgy” or have overlooked another solution. I was under the impression that a raycast is inclusive with its end points. Or are the endpoints exclusive?

Thanks,
BB


P.S.
If this has already been addressed in another thread I apologize for the duplicate post.