How to check collision between two entities

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

How to check collision between two entities

Post by ron »

as there are so many stuffs give for collision its quite confusing of wht to choose

i want that when two entities come in contact(just contact) at tht instance i want to decrease the health of character.
so this is wht i planned
if(body1.collideswith(body2))
{
body1.health-=1;
}

any way to get this logic
cause if i just check for collision, then till the time when the bodies r in contact ,health will reduce, but i want with one contact 1 health should reduce from the total.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: How to check collision between two entities

Post by Norbo »

I would recommend using collision events. They can be accessed in the entity.CollisionInformation.Events property. There are events for initial collision, every frame the object is in collision, ending collision, and so on. I would recommend sticking to the deferred versions (past tense naming) for thread safe operations.

Some documentation about collision events can be found here:
http://bepuphysics.codeplex.com/wikipag ... umentation
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: How to check collision between two entities

Post by ron »

any examples?
:)
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: How to check collision between two entities

Post by Norbo »

The getting started demo has some simple event integration:
http://bepuphysics.codeplex.com/wikipag ... umentation

The main source download's BEPUphysicsDemos project also includes a "FishInABarrelDemo" which uses collision events.
ron
Posts: 44
Joined: Sat Dec 11, 2010 7:25 pm

Re: How to check collision between two entities

Post by ron »

thnks for the reply
i am using the bounding box method
//update function
if (Entity.BoundingBox.Intersects(Entity2.BoundingBox))
{
damage = true;
}
if(damage ==true)
{
health--;
damage=false;
}
and its working fine
Post Reply