Page 1 of 1

Collision Detection

Posted: Mon Oct 22, 2012 8:58 pm
by bdpdonp
I am wondering if there is a way to do what I wish to accomplish or if the code will need to be modified.

To explain, consider a vessel in space with shields. The first collision detection, broad phase, is with the shields and a beam weapon. Collision would indicate intersection. But then some math would be needed by me to determine if the shield was penetrated. I would also need to know the point of intersection in object space to determine which shield was hit. If the beam penetrates then narrow phase occurs to determine if the target is hit and where.

This could also be a torpedo instead of a beam.

Can I do this with BEPU as it sits right now or will I need to make some code changes.

I just recently decided to try BEPU for this project so not real familiar with it yet.

Thanks

bdpdonp

Posts: 1
Joined: Wed Oct 17, 2012 11:19 am

Re: Collision Detection

Posted: Mon Oct 22, 2012 9:20 pm
by Norbo
Can I do this with BEPU as it sits right now
Yup!

I would not recommend handling instant-hit beam weapons using regular collision detection (that is, two entities collide and generate contacts). Instead, use a ray cast.

One option would be to call the Space.RayCast overload which returns all the hits along the ray. If you want to filter some irrelevant hits out, use the overload which also provides a filter delegate parameter. Scan through the list of hit objects; if you find a ship, check to see if the list also contains the shields intersection. If the list contains a shields intersection, handle the shields intersection first before deciding what to do with the ship intersection.

The ray cast method returns BroadPhaseEntry objects. These are objects which live in the broad phase; Entity objects do not live directly in the broad phase, but they have an EntityCollidable proxy which does. If you want to see if a ray cast hit an entity, try to cast the BroadPhaseEntry to an EntityCollidable. You can get the entity associated with an EntityCollidable from its Entity property.

The BroadPhaseEntry also has a Tag property which you can store an object in. It can be convenient to store your game logic information in this tag property so that you can grab it immediately from the ray cast result. The Entity also has a separate Tag property that can be used similarly, though it takes more work to grab from a ray cast (the EntityCollidable cast).

For non-instant hit weapons, like torpedos, you could make use of ray casts still if you wanted; just raycast from the previous to the current position of the projectile each frame to trace its path.

However, if you want regular physical interaction with the projectile, then just using an entity would probably be the better choice. Either use collision events or check the projectile entity.CollisionInformation.Pairs (look for contacts with nonnegative depth in each pair's Contacts list) list to see if it has collided with anything yet; if it has, then detonate it or whatever else. Depending on what it hits, you could choose different behaviors.

If you want an entity to ignore collisions with certain objects entirely, look into collision rules. An example usage of collision rules can be found in the CollisionFilteringDemo in the BEPUphysicsDemos.