Newbie: Use Chipmunk for labyrinth-like game?

Official forum for the Chipmunk2D Physics Library.
Post Reply
Juggle4Evr
Posts: 4
Joined: Sun Aug 01, 2010 4:41 am
Contact:

Newbie: Use Chipmunk for labyrinth-like game?

Post by Juggle4Evr »

Hi all.

I'm completely new to Chipmunk (coming with cocos2d for iPhone) and I've looked through some simpel sample programs.
What I want to do is a game for the iPad working like one of these labyrinth games where you see the labyrinth from straight above and have to move a marble through it by tilting the device.
Now my question: Can I use Chipmunk to program such a game? The samples, I've seen, are all using a "side-view" of the action, where the gravity is going straiht down. But for me I need a bird-exes view from above where the gravity vector is points perpendicular the the display of the device. The surface where the marble rolls, is not even but has ridges etc. so thats where the gravity comes to action. of course there should be bounces off when any obstacles are hit, etc.
Any ideas how to do that with Chipmunk or even better a sample program?

Thanks in advance,
Juggle4Evr
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Newbie: Use Chipmunk for labyrinth-like game?

Post by viblo »

My first thought is that it should be fairly simple to simulate, just have the gravity vector point in the direction the device is tilted? Not sure how it will work out with ridges and such, but maybe you can do it by attaching a constraint when the ball is within the area of the obstacle.. Guess it depends on what kind of obstacles you want. On the other hand, maybe its easier to go with a 3d engine instead? :)
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Newbie: Use Chipmunk for labyrinth-like game?

Post by slembcke »

Yeah, as long as you don't want super realistic behavior when interacting with obstacles that have depth it's easy. Just base the gravity vector off of the accelerometer. You can also fake interaction with holes and bumps pretty easily.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Juggle4Evr
Posts: 4
Joined: Sun Aug 01, 2010 4:41 am
Contact:

Re: Newbie: Use Chipmunk for labyrinth-like game?

Post by Juggle4Evr »

Hm, I think I have an idea now: I set the gravity vector according to the accelerometer as suggested so that I can "balance" the ball on the screen by tilting the device.
The surface where the ball is rolling, I treat as a kind of force that affects the ball. The direction and sze of this force depends on how the surface is curved and I somehow add this force to the ball to affect the movement (in adition to gravity and inertial forces that are handled by Chipmunk (I hope)).
Think, this could work?
Anyway, I have never done anything yet with Chipmunk, so it'll be a some hard work to work out how to do that.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Newbie: Use Chipmunk for labyrinth-like game?

Post by slembcke »

Yeah, that should work fine.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Juggle4Evr
Posts: 4
Joined: Sun Aug 01, 2010 4:41 am
Contact:

Re: Newbie: Use Chipmunk for labyrinth-like game?

Post by Juggle4Evr »

I've now succeeded compiling my program with chipmunk and tried to implement some simple physics using this sample:
http://iphonedev.net/2009/05/25/cocos2d ... lerometer/
together with the bouncing ball sample for a start.

Now it works, I can control the sprite with the accelerometer.
But it feels like having a big mass and inertia, so I changed the body setup from:

cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, CGPointZero));

to

cpBody *body = cpBodyNew(0.0000001f, cpMomentForPoly(0.00000001f, num, verts, CGPointZero));

But: there is no feelable change, the sprite still follows the accelerator input very sluggish. I tried several values for mass and inertia, they seem to have no effect on the movement.
Any idea what the problem could be? I want the sprite to follow the device movements more direct.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Newbie: Use Chipmunk for labyrinth-like game?

Post by slembcke »

You need to change the force of gravity, not the mass of the objects. Objects with more or less mass all accelerate at the same speed.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Juggle4Evr
Posts: 4
Joined: Sun Aug 01, 2010 4:41 am
Contact:

Re: Newbie: Use Chipmunk for labyrinth-like game?

Post by Juggle4Evr »

Increasing the gravity only speeds up everything. But the movement stays as sluggish as before. What for is the definition of a bodies mass and inertia if it does not affect the way a body reacts to a force (the gravity)?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Newbie: Use Chipmunk for labyrinth-like game?

Post by slembcke »

You might need to be more specific when you say sluggish. Turning up the gravity amount should make them accelerate faster. I'm not sure I understand if that wasn't what you were referring to.

Heavy objects react less to forces, yes, but all objects regardless of mass fall at the same rate under gravity. Galileo had a famous experiment that proved this a few hundred years ago. The reason is because heavy objects have a larger force of gravity applied to them.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests