Page 1 of 1

How to check collision between two entities

Posted: Mon Jun 06, 2011 1:21 pm
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.

Re: How to check collision between two entities

Posted: Mon Jun 06, 2011 2:51 pm
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

Re: How to check collision between two entities

Posted: Mon Jun 06, 2011 7:21 pm
by ron
any examples?
:)

Re: How to check collision between two entities

Posted: Mon Jun 06, 2011 7:23 pm
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.

Re: How to check collision between two entities

Posted: Tue Jun 07, 2011 7:47 am
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