Preventtion of Physics Reaction

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Rademanc
Posts: 16
Joined: Sat Apr 25, 2009 4:21 pm

Preventtion of Physics Reaction

Post by Rademanc »

Hi. Is it possible to prevent a physics reaction?
Say you have a character that has a percentage chance of dodging a missile. If the missile hits the player and he is suppose to dodge it, how can you then make it go through him, instead of pushing him back?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Preventtion of Physics Reaction

Post by Norbo »

This is going to be a little annoying in v0.9.0 as most conditions other than isTangible aren't considered after a collision pair is created. You could hook an event on an entity (either the character or the missile) that fires when a collision pair is created with that entity using the (Entity).addEventHook(EventHandlerControllerCreatedImmediate eventHandler) method. In this method, you could set the missile's isTangible flag to false. This will eliminate the missile's narrow phase collision response- against everything. So though it will go through the player, it will go ahead and continue through the wall behind him unless you detect when the controller is removed using addEventHook(EventHandlerCollisionPairRemoved eventHandler) and enable the isTangible flag once again. This isn't perfect by any means either, however.

Another idea would revolve around creating a larger intangible 'margin' entity around the character which detects incoming missiles and adds the missile to the character entity's nonCollidableEntities list if its supposed to miss. This will prevent the creation of a collision pair between the character and the missile. When the missile exits the controller or is removed, it would need to be removed from the character's nonCollidableEntities list as well. This would require some tuning based on missile speed because, if the missile traveled fast enough, it would already be intersecting the character at the first time the margin detects a collision pair.

In the next version, collision pair validation takes place before every attempt at narrow phase collision detection rather than only at pair creation. This would allow you to add the incoming entity to the nonCollidableEntities list during the first controller created event and remove it on the controller removed event without any 'margin' shape.
Post Reply