Poor performance when ghost object overlaps many btBoxShapes [with video]
Posted: Sun Nov 11, 2018 12:04 am
Hi,
In my game, every unit (in this video, drones) has its own rigid body shape (in this case, tiny spheres) to control its own motion, and they also all have a large btPairCachingGhostObject to act as a "detection range" - to detect nearby enemies to target
This works perfectly in most situations, however today I noticed that when building a huge grid of walls (each is just a btBoxShape rigid body with mass 0) , as soon as a few of the drones' ghost objects overlap the mass of walls, performance tanks.
I actually already tried this suggestion: https://github.com/bulletphysics/bullet3/issues/1283 and unfortunately it didn't help.
(I used a derived needsCollision and needsResponse as the author did on Github, however if I used his needsCollision, the ghost objects stopped working entirely. I could only use his needsResponse and have them still work)
A few questions:
1. Is a ghost object even the right way to detect if enemies are near each unit? If not, what would work better?
2. If ghost objects are the right answer, am I using them correctly?
3. Has anyone else ran into this issue before?
Here's the video: https://www.youtube.com/watch?v=UnOQ_CBa87g
Note when the drones fly over all the boxes, performance tanks and eventually catches up again
snip from each drone spawning code that creates the ghost object:
Thanks for any suggestions you may have!
In my game, every unit (in this video, drones) has its own rigid body shape (in this case, tiny spheres) to control its own motion, and they also all have a large btPairCachingGhostObject to act as a "detection range" - to detect nearby enemies to target
This works perfectly in most situations, however today I noticed that when building a huge grid of walls (each is just a btBoxShape rigid body with mass 0) , as soon as a few of the drones' ghost objects overlap the mass of walls, performance tanks.
I actually already tried this suggestion: https://github.com/bulletphysics/bullet3/issues/1283 and unfortunately it didn't help.
(I used a derived needsCollision and needsResponse as the author did on Github, however if I used his needsCollision, the ghost objects stopped working entirely. I could only use his needsResponse and have them still work)
A few questions:
1. Is a ghost object even the right way to detect if enemies are near each unit? If not, what would work better?
2. If ghost objects are the right answer, am I using them correctly?
3. Has anyone else ran into this issue before?
Here's the video: https://www.youtube.com/watch?v=UnOQ_CBa87g
Note when the drones fly over all the boxes, performance tanks and eventually catches up again
snip from each drone spawning code that creates the ghost object:
Code: Select all
if (canAttack)
{
//attackRange Ghost Object
instanceData[thisLocation].myAttackRangeGhostObject = new btPairCachingGhostObject();
instanceData[thisLocation].myAttackRangeGhostObject->setCollisionShape(myAttackRangeGhostShape);
instanceData[thisLocation].myAttackRangeGhostObject->setWorldTransform(btTransform(btQuaternion(0, 0, 0, 1), btVector3(spawnLocation.x, spawnLocation.y, spawnLocation.z)));
instanceData[thisLocation].myAttackRangeGhostObject->setCollisionFlags(instanceData[thisLocation].myAttackRangeGhostObject->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
world->physicsModule->dynamicsWorld->addCollisionObject(instanceData[thisLocation].myAttackRangeGhostObject, COL_FRIENDLY_SENSORTRIGGERS, friendlySensorTriggersCollidesWith);
instanceData[thisLocation].myAttackRangeGhostObject->setUserIndex(-100 - myIndex);
instanceData[thisLocation].myAttackRangeGhostObject->setUserIndex2(-100 - thisLocation);
}