Unplayable performance with terrain and ghost object

Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Unplayable performance with terrain and ghost object

Post by Mako_energy02 »

I'm setting up a level in my game, in it there is a static btRigidBody(both mass is set and the static collision flag is manually set) being used as the terrain. Also a part of the level I have a large btPairCachingGhostObject that overlaps the terrain, which performs checks and runs game logic based on those checks. It needs to be there. Unfortunately it seems that even though the ghost object has collision response disabled(and I've tried setting it as static as well), it still behaves as if it's detecting a collision, or at least that is my best guess as I am getting <0.1 FPS while they overlap.

What can I do to make them ignore each other and not nuke my performance?
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Unplayable performance with terrain and ghost object

Post by dphil »

Try setting the collision group of the terrain and the collision mask of the ghost object such that they produce a bit-wise & result of 0. For example, by setting the ground's group to 2, the ghost's mask to everything but 2 (ie. 65533 in decimal), and all other objects (which the ghost should detect) to any collision group other than 2 (I think the default is group 1, so you probably don't need to touch other objects).
Something like that, anyway. Then the physics engine should completely ignore their overlap.
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Unplayable performance with terrain and ghost object

Post by Mako_energy02 »

I looked a bit into doing that, and it seems Bullet does that for me, or at least is supposed to. Specifically lines 398-400 in btDiscreteDynamicsWorld.cpp, it does all the checks and sets the appropriate sane default filters and masks. In the case of how I have configured my bodies(ghost objects default to static and don't really ever change, due to the lack of mass and I'm manually setting my terrain as static) it should set the filter and mask to exactly the same as what I'd set if I was doing it manually. They are both static, and should be set to ignore other static objects...
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Unplayable performance with terrain and ghost object

Post by dphil »

Can you check the ghost's contents (iterate over its pair cache) at run-time and confirm that it is indeed detecting a collision with the ground? If so, then the collision mask isn't doing what we think it is (or ghost objects operate differently than I think they do).
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Unplayable performance with terrain and ghost object

Post by Mako_energy02 »

Confirmed...the terrain appears inside the ghostobject's cache.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Unplayable performance with terrain and ghost object

Post by dphil »

Hm, I know that setting the filters correctly does cause ghost objects to ignore certain rigid bodies - this is currently being done in some of our simulations. So, something seems to be wrong with your collision filter group/mask (though I agree the default settings on the lines you specified *look* ok). Two things:

1) Are you using addRigidBody for your ghost object as well as the ground? For ghost objects I believe you should use addCollisionObject (though I'm not sure your issue is due to this).
2) Try explicitly specifying your own collision groups/masks to do what you want. As a simple test:

Code: Select all

short int groundGroup = 1;
short int ghostGroup = 2;

world->addRigidBody(ground, groundGroup, btBroadphaseProxy::AllFilter ^ ghostGroup);
world->addCollisionObject(ghost, ghostGroup, btBroadphaseProxy::AllFilter ^ groundGroup);
Then see if the ghost is still picking up the ground...
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Unplayable performance with terrain and ghost object

Post by Mako_energy02 »

Well, this is slightly embarrassing. I decided to debug it to see exactly what values were being passed where...and along the chain of code I found a long lost line of code I made when I was first implementing ghost objects where I was setting them to be a sensor trigger and collide with everything that isn't also a sensor trigger. I amended it to also make an exception for static objects if it was also a static object and now it works perfectly.

Thanks for all your help dphil.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Unplayable performance with terrain and ghost object

Post by dphil »

No problem, glad you found the issue! Happy coding.