ignoring collisions on certain objects

Jun 14, 2010 at 7:28 AM

Hi,  I'm using the OOPS! framework and it's working great for me, but I wanted to find your opinion on the best way to do something.

I want to have rigid body objects dynamically enter and leave gameplay.  There is a gameplay stage and I drop physics objects into the game, 

they interact with the players, and at some point they 'break' and then I want to remove them from game until i decide to reactivate them and drop them back into the gameplay stage.


The way I'm implementing this right now is:

At the start of game, load all the rigid body objects into memory and add them to the physics system.  They are invisible and positioned offscreen and have their RigidBodyFlags set to RigidBodyFlags.Static.  


When I need to bring an object into the game, I position it over the gameplay stage, and set it's RigidBodyFlags to RigidBodyFlags.AutoDisable, and then it will fall into the game.  

When I need to remove an object form the game, I update its transform to put it out of the gameplay area and reset its RigidBodyFlag to RigidBodyFlags.static. 


Is this the best way to do this?  Or is there a way to effectively tell the physics system to completely ignore a rigid body?  I'm guessing that this is still wasting some resources, since the game is still checking for collisions between active rigid bodies and the static ones I have offscreen.  The way I'm doing it seems to be working, but I'd like to know if there is a better way.  

Thank you for any insight you can give me for this, and thanks so much for providing the awesome physics framework! 



Jun 14, 2010 at 7:37 AM

And then a follow-up question, is it ok for me to be changing the flags on the rigid body objects whenever I want?  Or is there a specific time I should do that, such as between calls to physics.endUpdate() and physics.beginUpdate()? 




Jun 16, 2010 at 3:15 AM

Hi cupcakesmcgee! :)

What you are doing is pretty clever.  I actually haven't really thought about dynamic rigid bodies much.  You can, of course remove items from the phyisics service and hold onto inactives in an external list but the way you are doing it is much better, performance-wise.  Good idea!  You also have CollisionFlags/CategoryFlags that may help with this if it makes things easier.  Otherwise, I'd keep as is.  I may put some thought into this for a future release.

Regarding changing the flags on rigid bodies, the safest place to change the flags is between EndUpdate and BeginUpdate.  You can also add an IPhysicsListener or use ICollisionCallback (if collisions cause the need to chang flags).  In the case of a collision callback the rigid bodies involved in the collision can have their flags changed but you must invalidate the collision (return false) in this case.

Good luck with your game!