Platformer Problems in Chipmunk

Official forum for the Chipmunk2D Physics Library.
Post Reply
tomleese
Posts: 4
Joined: Tue Nov 29, 2011 5:08 pm
Contact:

Platformer Problems in Chipmunk

Post 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?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Platformer Problems in Chipmunk

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
tomleese
Posts: 4
Joined: Tue Nov 29, 2011 5:08 pm
Contact:

Re: Platformer Problems in Chipmunk

Post by tomleese »

Thanks! I'll look through your code and see if I can get mine working.
tomleese
Posts: 4
Joined: Tue Nov 29, 2011 5:08 pm
Contact:

Re: Platformer Problems in Chipmunk

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Platformer Problems in Chipmunk

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
tomleese
Posts: 4
Joined: Tue Nov 29, 2011 5:08 pm
Contact:

Re: Platformer Problems in Chipmunk

Post by tomleese »

Ok, thanks. I'll take a look through that.
bridger
Posts: 1
Joined: Sun Dec 13, 2015 1:14 pm
Contact:

Re: Platformer Problems in Chipmunk

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests