Platformer Problems in Chipmunk

Official forum for the Chipmunk2D Physics Library.

Platformer Problems in Chipmunk

Postby tomleese » Tue Nov 29, 2011 5:15 pm

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?
tomleese
 
Posts: 4
Joined: Tue Nov 29, 2011 5:08 pm

Re: Platformer Problems in Chipmunk

Postby slembcke » Tue Nov 29, 2011 5:57 pm

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/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Platformer Problems in Chipmunk

Postby tomleese » Tue Nov 29, 2011 6:14 pm

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

Re: Platformer Problems in Chipmunk

Postby tomleese » Sun Dec 04, 2011 1:51 pm

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.
tomleese
 
Posts: 4
Joined: Tue Nov 29, 2011 5:08 pm

Re: Platformer Problems in Chipmunk

Postby slembcke » Sun Dec 04, 2011 3:13 pm

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/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Platformer Problems in Chipmunk

Postby tomleese » Sun Dec 04, 2011 3:23 pm

Ok, thanks. I'll take a look through that.
tomleese
 
Posts: 4
Joined: Tue Nov 29, 2011 5:08 pm

Re: Platformer Problems in Chipmunk

Postby bridger » Sun Dec 13, 2015 1:16 pm

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!
bridger
 
Posts: 1
Joined: Sun Dec 13, 2015 1:14 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests

cron