Attraction Local Gravity

Official forum for the Chipmunk2D Physics Library.

Attraction Local Gravity

Postby debug » Sun Nov 23, 2008 8:17 pm

Is there a way to make a body have it's own gravity so that it attracts other bodies?

The behavior i am after is based on mass vs body gravity bodies are attracted to the body with high gravity in addition to normal space gravity.

adversely if it is an interaction with something of infinite moment then the attraction would be opposite the body would be pulled towards the static body
debug
 
Posts: 19
Joined: Sun Nov 23, 2008 4:42 pm

Re: Attraction Local Gravity

Postby slembcke » Sun Nov 23, 2008 11:06 pm

In the trunk code, I added a demo of planetary gravity. http://code.google.com/p/chipmunk-physi ... o/Planet.c

Take a look at planetGravityVelocityFunc(). This is set as the velocity update function for the bodies added to the space.
Code: Select all
body->velocity_func = planetGravityVelocityFunc;


The velocity update function feature exists in the latest 4.1.0 stable as well.
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: Attraction Local Gravity

Postby debug » Sun Nov 23, 2008 11:17 pm

Thanks mate, awesome SDK you got here looking pretty neat and not bad feature wise

Is there some way to tell specific bodies to not obey spacial gravity?
debug
 
Posts: 19
Joined: Sun Nov 23, 2008 4:42 pm

Re: Attraction Local Gravity

Postby debug » Sun Nov 23, 2008 11:25 pm

Oh i see i guess i would just override the velocity function on those objects and set gravity to 0
debug
 
Posts: 19
Joined: Sun Nov 23, 2008 4:42 pm

Re: Attraction Local Gravity

Postby debug » Sun Nov 23, 2008 11:29 pm

I tested this function out and if i make a box around the screen and fire a small box or triangle anywhere on the screen it always ends up smack in the top left corner of the screen when i would expect it to slam into the nearest static segment to its originating position

i basically need a rigid body that i can control manually to a degree guiding its downward fall against normal gravity whilst this rigid body is attracting resting or falling rigid bodies around it

additionally when it gets close to a static body it should be pulled not irrecoverably towards it.

in other physics systems this can be achieved by making things attracted by force to each other and i would love to avoid setting up springs for things within a range every frame and removing springs as things fall out of a sphere of influence.
debug
 
Posts: 19
Joined: Sun Nov 23, 2008 4:42 pm

Re: Attraction Local Gravity

Postby slembcke » Mon Nov 24, 2008 1:27 am

The function that I pointed you at simply pulls things towards (0,0) nothing more. You can just apply forces to objects in Chipmunk if you find that easier.

It sounds like what you want to do is to have every collision shape in the space have gravity that is applied to every other object. Chipmunk's collision detection doesn't calculate closest features, so you will need to find some way to do that on your own. Using the distances between the centers of objects would be simpler, though not quite what you want. You also should realize that calculating forces that act between every pair of objects gets expensive very fast. Every time you double the number of objects, you quadruple the amount of processing that needs to be done.
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: Attraction Local Gravity

Postby debug » Mon Nov 24, 2008 11:34 am

I was thinking of something like "vector fields" / "force fields" as you would see in Physx or Havok where you define a spatial representation of a force that is part of the force solving for the physics engine which you can move around and modify then when things are colliding with the force field space their velocity is modified based on a function of that space.

How would i go about making some kind of pseudo force field system in chipmunk or is it an option for something you would like to make available to the system allowing predefined and customizable spatial forces such as Brownian motion and vortices.
debug
 
Posts: 19
Joined: Sun Nov 23, 2008 4:42 pm

Re: Attraction Local Gravity

Postby ehudros » Sat Dec 26, 2009 12:40 pm

This is a very old thread, I know, but it seems to be exactly what I'm after as well.
Is there a way to achieve what debug is talking about? Let's say I have several planets, all having different gravities. What would be the best way to simulate that?
ehudros
 
Posts: 17
Joined: Fri Oct 12, 2007 8:59 pm

Re: Attraction Local Gravity

Postby slembcke » Sun Dec 27, 2009 11:51 am

One of the new demos shows how to set up planetary gravity. To have more than one planet, simply calculate the gravity for each planet separately and add them together.
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


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 0 guests