Hi all,
I was wondering if any of you had any ideas as to how gravity wells should be properly implemented. By that I mean designating points on the space to which objects can be attracted, like a black hole or a similar massive object.
My first idea was to simply calculate the vector to the gravity well at every tick using the common formula of gravitational acceleration, and add that vector to the velocity of the body, or apply an impulse using the same vector. Both these approaches proved problematic, however, since when the object gets close enough the gravity vector becomes huge, which causes the object to simply shoot past the center and end up offscreen (and since the distance is now pretty far, the object doesn't gravitate back).
To mitigate this, I tried making sure the object's velocity never causes it to go past the center, and this works. However it yields the effect of the objects slowing down as they approach the gravity well, which is not the effect I want.
Has anyone implemented a semi-realistic looking gravity well?
Gravity wells?
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Gravity wells?
You should look at the planet demo. It uses an integration function to apply the forces. It is also "realistic" to have the forces continue to increase the closer the object gets. If you want to prevent the forces from getting too large, you can add a collision shape to prevent objects from getting too close or simple clamp the force it applies to a maximum.
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: 2
- Joined: Sun Jun 13, 2010 9:51 pm
- Contact:
Re: Gravity wells?
Thanks, that really helped! Didn't know you could change the velocity function. Much appreciated.
Got any tips on making the body slow down and stop eventually at the center of the gravity well?
Got any tips on making the body slow down and stop eventually at the center of the gravity well?
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Gravity wells?
Well I guess what you want then is not really a gravity well, and not something that is easily done in a stable way using only forces. Also, because what you want is not really based in simple or real physics there is going to be a million ways to implement it each with it's own feel. It also means that there isn't really a simple formula that you can point to and say it's the correct way to do it.
I might first try to implement something like that using an attraction force and some simple damping. The attraction force would just be a normal gravity force, and the damping a simple velocity = velocity*damping applied every frame. Pick a radius around the well, when an object enters the circle, give the attraction force a linear falloff from the gravity value at the edge (Like a gravity distance plot of a real planet when you enter it's surface). For that damping, interpolate the damping from 1 some value as you get further into the circle. The intended effect of all this is that you are being attracted to a ball of gas. As you enter the ball, the amount of gravity drops off the further into the surface you get, and the drag increases the deeper you go into it's atmosphere.
You might need to use logarithmic interpolation (a*pow(b/a, t)) for the damping value to make it feel right. Linear interpolation might cause the damping to feel too solid.
I might first try to implement something like that using an attraction force and some simple damping. The attraction force would just be a normal gravity force, and the damping a simple velocity = velocity*damping applied every frame. Pick a radius around the well, when an object enters the circle, give the attraction force a linear falloff from the gravity value at the edge (Like a gravity distance plot of a real planet when you enter it's surface). For that damping, interpolate the damping from 1 some value as you get further into the circle. The intended effect of all this is that you are being attracted to a ball of gas. As you enter the ball, the amount of gravity drops off the further into the surface you get, and the drag increases the deeper you go into it's atmosphere.
You might need to use logarithmic interpolation (a*pow(b/a, t)) for the damping value to make it feel right. Linear interpolation might cause the damping to feel too solid.
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