Can a shape have it's own gravity.

Official forum for the Chipmunk2D Physics Library.
Post Reply
nickhomme
Posts: 1
Joined: Sat Sep 11, 2010 4:11 pm
Contact:

Can a shape have it's own gravity.

Post by nickhomme »

Is it possible for have an object/shape to have its own gravity. It would basically be like a planet where when things float by the planet it would start to draw them closer depending on the distance between the object and the planet.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Can a shape have it's own gravity.

Post by slembcke »

Not trivially, but you can calculate your own forces each frame or use integration callbacks to calculate gravity on the fly. Check out the Planet demo that comes with Chipmunk.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jason_rogers
Posts: 81
Joined: Fri Aug 27, 2010 1:00 am
Contact:

Re: Can a shape have it's own gravity.

Post by jason_rogers »

this might be a silly idea but if you want a simple physical pull towards your planet you could use a dampend spring constraint between your planet and your object and remove the constraint if the object gets to far.

not the cleanest solution for a game that depends on the gravity on the long run but maybe less tedious than calculating gravity on the flight ^^
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Can a shape have it's own gravity.

Post by slembcke »

While that would sort of work, it wouldn't produce a very gravity like force. Gravity gets weaker the farther away you get, springs get stronger.
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