Page 1 of 1

Categorizing collisions

PostPosted: Thu Jan 10, 2008 7:03 pm
by Ezequiel
Hello, I already used chipmunk to replace my homemade physics engine.

I was wondering, how would you implement the following:

You have a sprite A and a "floor" B. Sprite A starts at a certain height over the floor B, so they aren't in contact.

A falls on the floor. Now I want the AI of A to start walking, seeking doors, and so on, since it is contacting A.

The physics part and the AI are already programmed and working. The problem I'm having is how to tell the AI "you are on the ground".

I'm trying to implement a callback function for collisions between objects of the same type of A and floor objects. The problem with this approach is that I'm afraid the function will be called once per simulation step, since the objects will be in contact most of the time (is that so?), and of course I don't need that, I only need to warn the AI that it is on a ground.

Any ideas are welcomed, if you want to take a peek at the project and source you can go here:

Thank you

Re: Categorizing collisions

PostPosted: Mon Jan 14, 2008 2:53 am
by supertommy
Are you using the C interface? In that case, you can probably get exactly what you want by giving the ground and the player unique collision_type values, and implementing a collision pair function. Search for "Collision pair functions" in the documentation for a more in-depth explanation. You should also look at Demo1.c in the Demo subdirectory in the chipmunk source. The collFunc() function is a collision pair function.

Re: Categorizing collisions

PostPosted: Sat Jan 19, 2008 1:24 pm
by Ezequiel
Thank you... I implemented something already. What I did is keeping a record of the last time the surfaces hit. Then the AI pop the records and act as if it was standing on the ground.

The problem wasn't detecting the collision but knowing how to make a difference between a bounce and a permanent collision (for example)