Categorizing collisions

Official forum for the Chipmunk2D Physics Library.

Categorizing collisions

Postby Ezequiel » Thu Jan 10, 2008 7:03 pm

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: http://code.google.com/p/cavemen/

Thank you
Ezequiel
 
Posts: 8
Joined: Thu Jan 10, 2008 1:50 pm

Re: Categorizing collisions

Postby supertommy » Mon Jan 14, 2008 2:53 am

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.
supertommy
 
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm

Re: Categorizing collisions

Postby Ezequiel » Sat Jan 19, 2008 1:24 pm

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)
Ezequiel
 
Posts: 8
Joined: Thu Jan 10, 2008 1:50 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 0 guests

cron