Page 1 of 1

ObjectiveChipmunk Gravity (cocos2d 2.0)

Posted: Mon Jul 02, 2012 10:24 am
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 :)

Re: ObjectiveChipmunk Gravity (cocos2d 2.0)

Posted: Mon Jul 02, 2012 10:55 am
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.

Re: ObjectiveChipmunk Gravity (cocos2d 2.0)

Posted: Mon Jul 02, 2012 10:58 am
by bkervaski
Ahh! Got it, perfect. Thanks :) :) :)