How to externally identify a Collidable

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

How to externally identify a Collidable

Post by Tengato »

Hi,
My game consists of actors that may contain collision/physics components in the form of BEPU Terrain or Entity objects that participate in the Space simulation. When the actor's game behavior needs to know about collisions that occur inside the simulation, it subscribes to the InitialCollisionDetected event of its Entity. Now the problem I have is that inside this event handler I am given the Collidable object 'other', but what I really want is to take some action on the actor that owns that Collidable, say to deduct health or whatever. What is the best way to do this?

Ideally, I could place an integer actor id on the BroadPhaseEntry object when an actor is initialized with a physics component. Sometimes objects have Tag properties for this purpose, but I found that BEPU doesn't like finding unexpected values in Tag properties or I'm using it incorrectly... I could also maintain a big hashtable of all collidables and their actor ids, but that seems a bit troublesome.

Thanks!!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: How to externally identify a Collidable

Post by Norbo »

Using the Tag properties would be the easiest option. The only case where the engine itself uses the Tag property is the CharacterController.Body.CollisionInformation.Tag. That tag can be replaced with other tags so long as those other tags also implement the ICharacterTag interface properly. (Note that I may, at some point, remove the usage of tags from the character controller.)

Entity objects also have a Tag property. This is separate from the BroadPhaseEntry.Tag property, which would be the Entity.CollisionInformation.Tag. You can get the Entity associated with a Collidable, if any, by casting the Collidable to an EntityCollidable and checking its Entity property. Nothing in the engine currently uses the Entity.Tag property.
Tengato
Posts: 6
Joined: Thu Oct 10, 2013 4:45 pm

Re: How to externally identify a Collidable

Post by Tengato »

Aha, that explains it - I did try to use the Tag property of the character controller once before to handle collisions with players a little bit differently. But I was scared away from that approach when I got error messages about the type of objects allowed in that property. Now with your advice on using the Tag properties, it will be easy to get the features I'm after. Thanks so much Norbo!! :D
Post Reply