Page 1 of 1

Getting all entitys inside a sphere

Posted: Sun Dec 09, 2012 7:11 pm
by Zardoz
Hi! I'm making a quick and dirty FPS like game, and I'm using Bepu to ru nthe physics of the game.
There is a way to use Bepu to find all entities that are inside a Sphere ? Could be usefull to advice the actors attached to these entitys and give damage by a explosion.

Re: Getting all entitys inside a sphere

Posted: Sun Dec 09, 2012 8:02 pm
by Norbo
The broad phase supports queries:

Code: Select all

Space.BroadPhase.QueryAccelerator.GetEntries(boundingSphere, listOfResults);
'listOfResults' will contain the set of BroadPhaseEntry objects whose bounding boxes touched the given bounding sphere.

A BroadPhaseEntry is something that lives inside the broad phase. Entity objects do not directly inherit from BroadPhaseEntry; instead, they have a collision proxy stored in the Entity.CollisionInformation property of type EntityCollidable which inherits from Collidable which inherits from BroadPhaseEntry.

So, to determine if a BroadPhaseEntry is associated with an Entity, try to cast the BroadPhaseEntry to an EntityCollidable. If it succeeds, use the EntityCollidable.Entity property to get the entity.

Another option is to store a game logic object in the BroadPhaseEntry.Tag property that stores whatever helpful information you want and access that directly.