Cancelling the solver when detecting collision

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Tengato
Posts: 6
Joined: Thu Oct 10, 2013 4:45 pm

Cancelling the solver when detecting collision

Post by Tengato »

Hi,
I just implemented pickups in my game using a sphere entity (with locked rotation), so they can tumble to the ground when dispensed, bump into other inert objects, etc. The pickups handle the Sphere's InitialCollisionDetected event, during which they check to see if the colliding object is a player and if so, give the player their gameplay effect. After the Space Update is completed where the pickup was used, it is despawned.

A player typically runs straight through the pickup, so they experience a little bump when they collide with it. No surprise, it has some mass and it is being pushed away by the player. In practice though, this is unpleasant and I'd like to remove that hiccup.

Is it possible to avoid running the solver for a collision from the InitialCollisionDetected event handler? I tried setting the pair.CollisionRule or the sender.Entity.CollisionInformation.CollisionRules to NoSolver, but that didn't seem to work.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Cancelling the solver when detecting collision

Post by Norbo »

InitialCollisionDetected and other past-tense named collision events are 'deferred' until the end of a time step, so they're too late to change the collision rule. (Their purpose is to make logic in the average case easier to manage by dispatching from the thread that calls Space.Update.)

Present-tense named collision events, like DetectingInitialCollision, fire from within collision detection, so the collision rule could technically be changed there.

However, it's probably easiest to put power ups into one CollisionGroup, characters into another, and then set a NoSolver rule between them. This would avoid the need for any state changes within an event. More information about collision rule evaluation can be found in the documentation.
Tengato
Posts: 6
Joined: Thu Oct 10, 2013 4:45 pm

Re: Cancelling the solver when detecting collision

Post by Tengato »

Thanks for pointing me in the right direction, Norbo! Once I figured out how to use CollisionGroups, it was easy to get things working the way I wanted. :D
Post Reply