Character capsule, how to detect contact with other objects?

ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Character capsule, how to detect contact with other objects?

Post by ola »

Hi all,

I've made a character capsule standing upright that I move around by setting velocities and applying impulses. I set the angular factor on this capsule to zero, so that it won't tip over.

The capsule slides around on the ground, and I can hit other objects and jump on them, run it over by a vehicle. Things are starting to work nicely!

Now I would like to know if the capsule is touching something. For example, I'd only apply a jump impulse if the capsule is standing on something to begin with. And walking should not be possible while in free fall..

What would be the best way to check for this?

Also, I am uncertain if I'm doing the movement code in the right place. Now, the main loop in the program looks something like this:

Code: Select all

while(1) {
 int max_iter = 10;
 physics_world_->stepSimulation(dt_, max_iter);
    
 // Update objects
 for(list<WbWorldObject*>::iterator i = worldobject_list_.begin();
     i != worldobject_list_.end(); ++i)
    {
    WbWorldObject* av = *i;
    av->timeStep(dt_, this);
    }
}
here, the character control happens inside one of the av->timeStep functions (together with animations, etc).

Maybe a better way would be to implement a character class similar to the raycar vehicle, and put the character control inside the updateVehicle() function that is called from within stepSimualation?

Best regards,
Ola
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

Thanks for the feedback.

A demo for a character controller should be added indeed. Also the vehicle demo still needs brakes, before picking up more work :)

In the meanwhile, there are several ways of detecting collisions between objects. One of them is the custom nearCallback. See the CcdPhysicsDemo for USE_CUSTOM_NEAR_CALLBACK.
Another method is to intercept the CustomMaterialCombinerCallback, see ConcaveDemo.

Both are not so very easy to use. Another brute force method is to traverse the contact manifold array, and search for your object. See CollisionInterfaceDemo for an example.

Hope this helps,
Erwin
skala
Posts: 1
Joined: Mon Mar 12, 2007 6:19 pm

Post by skala »

i'd appreciate the character controller demo as well :P

thank you
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Post by ola »

Hi Erwin,

thanks! I went for the simple brute force method for now, and that works. I think I'll try to do something with a raycast later (similar to what the btVehicle does) so to create an impulse on the thing I'm jumping off as well.

Best regards,
Ola
Zimbarbo
Posts: 14
Joined: Thu Jun 28, 2007 2:26 pm

Setting NearCallback

Post by Zimbarbo »

Here is what I am doing (C# ver). Please correct me if this is the wrong thing...

In the CollisionDispatcher, I am just adding my collision callback function to the NearCallback:

Code: Select all

_collisionDispatcher.NearCallback += MyCollisionCallback;
This gets called along with the default collision callback in the near phase down in the Dispatcher. I only have one dynamic guy running around, but I am hoping this will be of use when there are more as you can get the two collision objects out of the first arg.
tjloughl
Posts: 23
Joined: Wed Oct 03, 2007 4:03 am

Re: Character capsule, how to detect contact with other objects?

Post by tjloughl »

So I used the code from the demo to create a custom callback. However, the callback is getting called for some of my objects even though they aren't colliding (they are 12m or above the other object). It is a bounding box colliding with and terrain triangle mesh. Any ideas why this would be happening?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Character capsule, how to detect contact with other objects?

Post by Erwin Coumans »

tjloughl wrote:So I used the code from the demo to create a custom callback. However, the callback is getting called for some of my objects even though they aren't colliding (they are 12m or above the other object). It is a bounding box colliding with and terrain triangle mesh. Any ideas why this would be happening?
What is the terrain? A btBvhTriangleMeshShape?

It is best to avoid the btStaticPlaneShape in real games/applications, it has an infinite AABB and always generates AABBs.

Hope this helps,
Erwin
tjloughl
Posts: 23
Joined: Wed Oct 03, 2007 4:03 am

Re: Character capsule, how to detect contact with other objects?

Post by tjloughl »

The problem was that the collision I was getting was the proximity collision. I figured out how to get the actual collision and it works great now. Also, I am looking to do explosions as I posted elsewhere. Is scaling a rigid body real-time a bad idea? THANKS