Detect when object on the ground

Official forum for the Chipmunk2D Physics Library.
Post Reply
Guy
Posts: 1
Joined: Mon Feb 11, 2008 10:08 pm
Contact:

Detect when object on the ground

Post by Guy »

I'm making a platformer, and I represent the player as a circle and the ground as a bunch of line segments. Since the movement and jump keys should only work when the player is touching the ground, how do I tell when there's contact between the player and the ground?
Blue Prawn
Posts: 22
Joined: Thu Jan 03, 2008 1:36 pm
Contact:

Re: Detect when object on the ground

Post by Blue Prawn »

Have a look in the demos either from the Chipmunk sources or the moon-buggy, the contacts are drawn with red points.

In short the cpSpace structure has a member arbiters (type cpArbiter array) which has two members a and b of type cpShape (the 2 shapes of the contact), the cpArbiter structure has members contacts and numContacts.

As on each contact you can get back the two shapes involved, then you can use the ids of these shapes to know if one of them is your sprite.

The only trick is to make the contact check inside each loop made on substeps, because if you do it in your main drawing loop and substeps is set to 5 (for example), the contact check will be made only 1/5 of the time.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests