Page 1 of 1

Platformer Problems in Chipmunk

Posted: Tue Nov 29, 2011 5:15 pm
by tomleese
I am writing a platform game using Chipmunk physics and I am wondering what the best way of doing it is. So far, I have removed gravity and I'm manually changing the velocities of the objects to perform what I want. However, I am getting a problem where objects seem to be really bouncy even though the elasticity is set to 0.

I am wondering if using forces is a better way of doing it, and if so, I would need friction to keep things from sliding everywhere. However, how would I stop objects getting "stuck" to the side of a wall if the user keeps pressing right or left?

Re: Platformer Problems in Chipmunk

Posted: Tue Nov 29, 2011 5:57 pm
by slembcke
Fortunately, I have a good example that I can point you towards. I recently entered a game contest and our team made a platformer. You can check out the source code here:
https://github.com/maximile/Your-Story

In particular I made a custom velocity update function for the body that does a lot of the player control magic:
https://github.com/maximile/Your-Story/ ... cter.m#L40

It uses surface velocities + friction to give the player nice movement even on moving platforms/surfaces, and Mario-style variable jump heights. Feel free to ask questions as there isn't a lot of comments in the code explaining how it works.

Re: Platformer Problems in Chipmunk

Posted: Tue Nov 29, 2011 6:14 pm
by tomleese
Thanks! I'll look through your code and see if I can get mine working.

Re: Platformer Problems in Chipmunk

Posted: Sun Dec 04, 2011 1:51 pm
by tomleese
I am wondering how you managed to check whether the player is touching the ground correctly. Currently I am making sure the Y velocity is greater than 0 when a collision is detected but that can be a bit inaccurate. Also, I would like to check whether the player is touching on object on the left or right so I can stop the user being able to move it.

Re: Platformer Problems in Chipmunk

Posted: Sun Dec 04, 2011 3:13 pm
by slembcke
I check the contact graph using cpBodyEachArbiter():
https://github.com/maximile/Your-Story/ ... bject.m#L3

Basically it picks the object that the player is standing on with the best (most upright) collision normal. I don't check left/right collisions because I'm moving the player using surface velocities, and it doesn't matter.

Re: Platformer Problems in Chipmunk

Posted: Sun Dec 04, 2011 3:23 pm
by tomleese
Ok, thanks. I'll take a look through that.

Re: Platformer Problems in Chipmunk

Posted: Sun Dec 13, 2015 1:16 pm
by bridger
I'm really late to this thread, but I wanted to say thanks to slembcke for posting the Your Story code. It has been a huge help in getting the platformer feel with Chipmunk!