ObjectiveChipmunk Gravity (cocos2d 2.0)

Official forum for the Chipmunk2D Physics Library.
Post Reply
bkervaski
Posts: 2
Joined: Fri Jun 29, 2012 3:00 pm
Contact:

ObjectiveChipmunk Gravity (cocos2d 2.0)

Post by bkervaski »

If I set my gravity to center shouldn't all my objects fall towards center (albeit slowly since it's not a strong value)?

Code: Select all

space.gravity = cpv(window.width/2, window.height/2);
Just trying to wrap my head around gravity, I know it needs a larger number to pull, but when I set to center my objects still fall to the upper right corner of my point system, now I'm confused.

Thanks for any help :)
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: ObjectiveChipmunk Gravity (cocos2d 2.0)

Post by slembcke »

That is the direction of gravity, not the "position" of gravity.

(0, -1) means gravity pulls downwards. (0, -1000) means gravity pulls downwards 1000x as strong. (1, 1) means gravity would pull to the upper right, etc.

If you want to implement planetary gravity, you'll need to create your own velocity integration function. I have a C example of that in the vanilla Chipmunk distribution: https://github.com/slembcke/Chipmunk-Ph ... o/Planet.c. Objective-Chipmunk doesn't fully wrap integration functions, but I have an example of a (position) integration function from Objective-Chipmunk here: https://gist.github.com/3033927.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
bkervaski
Posts: 2
Joined: Fri Jun 29, 2012 3:00 pm
Contact:

Re: ObjectiveChipmunk Gravity (cocos2d 2.0)

Post by bkervaski »

Ahh! Got it, perfect. Thanks :) :) :)
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests