bullet3
bullet3 copied to clipboard
btCollisionWorld::rayTest incredibly wrong/inaccurate
I was using btCollisionWorld::rayTest
to test gun bullet (bullet as in projectiles, not the library) collisions against obstacles; when I noticed bullets were going through obstacles too often and from blatant places (i.e. "There's now way Bullet is missing those raycast collisions").
So I started logging data to reproduce the problem locally.
I have a static btBoxShape: center = (0, 2.024, -3.0)
halfSize = 2.024000, 2.024000, 2.024000
.
const btVector3 rayFrom( -2.027535, 1.323740, -4.894639 );
const btVector3 rayTo( 2.506727, 1.292858, -2.102663 );
btCollisionWorld::ClosestRayResultCallback closestResults( rayFrom, rayTo );
closestResults.m_collisionFilterGroup = 0xFFFFFFFF;
closestResults.m_collisionFilterMask = 0xFFFFFFFF;
m_world->rayTest( rayFromWorld, rayToWorld, resultCallback );
This fails despite being blatantly going through the box (Box is the obstacle, the spheres are to and from):
I've defined USE_BRUTEFORCE_RAYBROADPHASE
to debug this problem but the problem remains.
What's most amazing is that if I swap from
and to
, it reports a collision!
I googled around and found a forum post from 2010 mentioning this exact problem.
I can't post there because registering is disabled and my findings matches theirs.
Bottom line is; I'm seeing that rayTest is so wrong and misses so many cases it is downright unusable.
This needs at the very least to be documented, the function maybe even disabled; and at best fixed.
I'm sorry for being this harsh, but it is really broken. I will have to roll down my own versions.