Kinematic does not collide with terrain

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Kinematic does not collide with terrain

Post by imtrobin »

Hi

I created a kinematic Entity and I'm trying to get it detect collision with a terrain without success.

sphere_ = new Sphere (new Vector3 (400, 800, 400), 3.5f);
sphere_.isAlwaysActive = true;
sphere_.addEventHook (new EventHandlerEntityUpdated (EventEntityUpdated));

sphere_.addEventHook (new EventHandlerInitialCollisionDetected (EventInitialCollisionDetected));
sphere_.addEventHook (new EventHandlerCollisionEnded (EventCollisionEnded));

space_.add (sphere_);


I set the linearvelocity of the entity and also the even the isDetector=true, but it doesn't register the collision. It can register collision with other dynamic Entities, just not the terrain.

sphere_.linearVelocity = new Vector3 (0, 5, 0);
sphere_.correctiveLinearVelocity = new Vector3 (0, 5, 0);
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Kinematic does not collide with terrain

Post by Norbo »

This is caused by the StaticTriangleGroup only producing triangles when active and physically simulated objects approach. Until this is addressed, you can try creating a dynamic entity with isTangible = false that follows the kinematic object around and activates triangles.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Kinematic does not collide with terrain

Post by imtrobin »

Are you planning to address this? Hmm, it would seem to be expensive to create another Entity to follow it.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Kinematic does not collide with terrain

Post by imtrobin »

Just to update, I tried a dynamic entity with isTangible = false, it does not fire the collision events too.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Kinematic does not collide with terrain

Post by Norbo »

The extra expense of an intangible object is relatively small. Collision/collision response is a very large portion of the overall cost, and intangible objects do not cause either.

The idea behind using the intangible object was not as a complete replacement of the kinematic object, as intangible objects will not trigger collision events. Rather, the intangible object will trigger the StaticTriangleGroup/Terrain to create triangles which can be tested against (either by a detector kinematic object or with explicit Toolbox collision queries). The produced triangles can be found by examining the (Entity).controllers list of the intangible object.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Kinematic does not collide with terrain

Post by imtrobin »

I have tried adding a intangible to follow the sphere but still no collision with terrain. This is my setup. Sphere is the kinematic entity I control by setting the velocity. Box is the intangible.

Code: Select all

 sphere_ = new Sphere (new Vector3 (400, 800, 400), 3.5f, 2);
sphere_.isAlwaysActive = true;
sphere_.makeNonDynamic ();

sphere_.tag = ship_; // my visual object which is following physics position

sphere_.addEventHook (new EventHandlerEntityUpdated (EventEntityUpdated));
sphere_.addEventHook (new EventHandlerInitialCollisionDetected (EventInitialCollisionDetected));
sphere_.addEventHook (new EventHandlerCollisionEnded (EventCollisionEnded));

space_.add (sphere_);

Entity intangible = new Box (Vector3.Zero, 10, 10, 20, 2);
intangible.isAlwaysActive = true;
intangible.isTangible = false;
intangible.tag = sphere_;  // to follow the kinematic entity
intangible.addEventHook (new EventHandlerEntityUpdated (EventFollowEntity));
space_.add (intangible);

public void                     EventFollowEntity (Entity sender)
{
   Entity parent = (Entity)sender.tag;

    sender.moveTo (parent.centerPosition);
 }

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

Re: Kinematic does not collide with terrain

Post by Norbo »

Though the triangles are activating due to the intangible object, the sphere is kinematic and not a detector so no contact points will be created and no events fired. Making it a detector will allow it to generate contacts against another kinematic object.

Another option would be to attach the 'collision pair created' event to the intangible object and monitor its collisions using specific collision queries (such as those in the toolbox).

By the way, if you leave off the mass parameter in the entity constructor, it will default to being a kinematic entity- avoiding the need to call makeNonDynamic.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Kinematic does not collide with terrain

Post by imtrobin »

I'm a little more confused now. So what you are saying is to create a detector entity (istangible=true) which follows the original kinematic entitiy. That seems to make more sense that an Entity istanglible = false.

Anyway, I gave that a try, and set the follow enitity to isDetecter=true and istangible=true, and moved the event callback to this entity, then those get fired when colliding with terrain. Is that what you meant?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Kinematic does not collide with terrain

Post by Norbo »

So long as the geometry of your detector matches the geometry of your followed object, that would get the same results. The only difference between the method I suggested and yours is that the kinematic object (which already has the desired geometry) was a detector. There could be side effects of this approach if you wanted dynamic entities to normally collide with the object, since detectors do not undergo collision response.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Kinematic does not collide with terrain

Post by imtrobin »

Yes, I would need the kinematic to be collided with other dynamic. So it seems the only solution is to make another dynamic entity with isDetector = true that will follow the kinematic. I'm concerned about performance since I'm doubling my entity count like this.

BTW, I could not seem to get the intangible method you suggested to work. Can you describe in more detail e.g

1. create kinematic, isDetector=false
2. create intangible entity, dynamic, istangible=false, that follows kinematic
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Kinematic does not collide with terrain

Post by Norbo »

As an extension of the ideas in the other thread (http://www.bepu-games.com/forums/viewto ... ?f=4&t=507), here's how you could go about making the Terrain produce triangles.

1: Create an entity (Kinematic, isTangible = true, isDetector = false) representing your game object.
2: Create an entity (Dynamic, isTangible = false, isDetector = false) to follow your kinematic entity. Arbitrary geometry; just needs to have a bounding box which encloses entity 1.

The entity created in step 2 will force the Terrain to produce triangles when it comes close.

Now that you have Terrain triangles available to you and stored within the controllers (collision pairs) list of your intangible entity, your next task is to discover whether or not your entity from step 1 is colliding with any of them.

One method that does not involve contact generation or events would be to use one of the static Toolbox methods to compare each triangle against your kinematic object to determine if they are colliding (Toolbox.areObjectsColliding). We'll call this option A.


Another way to do it is to revise the initial approach. There's a couple of ways to do this, each with their respective downsides. This isn't necessarily an exhaustive list, but these methods are fairly straightforward.

B:
1: Create an entity (Kinematic, isTangible = true, isDetector = false) representing your game object.
2: Create an entity (Dynamic, isTangible = true, isDetector = true) to follow your kinematic entity. Must have geometry matching entity 1.

C:
1: Create an entity (Kinematic, isTangible = true, isDetector = true) representing your game object.
2: Create an entity (Dynamic, isTangible = false, isDetector = false) to follow your kinematic entity. Arbitrary geometry; just needs to have a bounding box which encloses entity 1.

Option B will collect contact points between the detector and appropriate objects. You'll need to watch out for dynamic entity collisions since they will generate a contacts against both the detector and normal entity (wouldn't be a big issue if you're only monitoring the events from the detector).

Option C centralizes the collision detection on the kinematic body, though dynamic entities colliding with it no longer undergo collision response (as it is a detector).


Option A may turn out to be the most controllable. B and C offer a little more automation.
imtrobin
Posts: 101
Joined: Thu Jun 11, 2009 3:03 am

Re: Kinematic does not collide with terrain

Post by imtrobin »

Excellent, thanks for the detailed explanations.
Post Reply