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
Attraction Local Gravity
-
- Posts: 19
- Joined: Sun Nov 23, 2008 4:42 pm
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Attraction Local Gravity
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.
The velocity update function feature exists in the latest 4.1.0 stable as well.
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;
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 19
- Joined: Sun Nov 23, 2008 4:42 pm
- Contact:
Re: Attraction Local Gravity
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?
Is there some way to tell specific bodies to not obey spacial gravity?
-
- Posts: 19
- Joined: Sun Nov 23, 2008 4:42 pm
- Contact:
Re: Attraction Local Gravity
Oh i see i guess i would just override the velocity function on those objects and set gravity to 0
-
- Posts: 19
- Joined: Sun Nov 23, 2008 4:42 pm
- Contact:
Re: Attraction Local Gravity
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.
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.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Attraction Local Gravity
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.
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 19
- Joined: Sun Nov 23, 2008 4:42 pm
- Contact:
Re: Attraction Local Gravity
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.
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.
-
- Posts: 17
- Joined: Fri Oct 12, 2007 8:59 pm
- Contact:
Re: Attraction Local Gravity
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?
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?
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Attraction Local Gravity
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 9 guests