Checking for collision at the bottom of a capsule?

Calneon
Posts: 1
Joined: Fri Feb 11, 2011 10:57 am

Checking for collision at the bottom of a capsule?

Post by Calneon »

I have a capsule shape representing my player character, I need to check whether the bottom of the capsule is in contact with another object in order to allow him to jump. I have searched a lot on collision callbacks and checked the wiki, but I can't get my head around it. I can set up the manifold using the code from the wiki but I have no idea how to tell my object when it is colliding, and I don't know how to tell it when only the bottom is colliding.

Could use some help, thanks.
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Checking for collision at the bottom of a capsule?

Post by Flix »

Well, it depends on what you used for your capsule shape (pair caching ghost object or regular rigid body). Character controllers are pair caching ghost objects.

Anyway in both cases you must iterate the collision manifold until you find btManifoldPoints for your body and any other collision object.
At this point, for each of them you must calculate the difference between your body "Center Of Mass" and the collision point in global space.
If the y component is > 0 it means that there is a collision point between your body and another object and that this point is below your body C.O.M. (usually you may want to test against a positive threshold).

I've recently posted the system I use for collision detection (http://bulletphysics.org/Bullet/phpBB3/ ... 91&start=0). If you use a regular rigid body for your capsule, you can easily call the runtime query btRigidBodyWithEvents::isOnABody(btScalar YThreshold), after you enable your body collision monitoring system, to do it (although I've never tested it, nor used for making a body jump...).
The difference is that my system uses an "average contact point" between the 2 bodies: I believe that for your purpose it should be better to test every single point instead...

Hope you get the general idea...