Gravity

BlitzMax Forums/BlitzMax Programming/Gravity

ImaginaryHuman(Posted 2005) [#1]
I am just wondering, is the amount of gravity that is exerted on an object some distance from the earth the same as the amount of gravity that would be exerted on it if the object was closer?

I don't need to know what the gravity equasions are. I don't understand them. What I want to know is, if I am modelling this in 2d and I have objects falling due to their weight, is it accurate to just add a constant value to their Y position or Y inertia each frame, or does the amount of gravity differ further from the surface of the earth?

And if it's a curve, what kind of curve?


JoshK(Posted 2005) [#2]
Gravity is greater as you get closer to the surface of the Earth, but only by a negligible amount.


ImaginaryHuman(Posted 2005) [#3]
Because of the great distance that the gravity pull spans out into space? What if it were scaled down?


DocFritz(Posted 2005) [#4]
That would mean, you crashed some physical laws of nature ;)
Whatever, the higher you go, the easier it is to achieve a bigger height. Just try it, will be way strange for the player ^^


TartanTangerine (was Indiepath)(Posted 2005) [#5]
Ummn objects don't fall according to thier wieght. A heavier object will not hit the ground before a lighter object.

All objects (near the earth's surface) experience a constant downward acceleration of g = 9.81 (m/sec)/sec, regardless of what their mass was.

Imagine you had two cannon balls of exactly the same shape and dimensions, one was hollow and the other soild.. if you dropped these from a great hieght at exactly the same time they would hit the floor at exactly the same time.

To summarize, we know the acceleration an object experiences (due to the gravitational attraction between the earth and the object) does depend on its height above the surface of the earth. However, if the object is reasonably close to the earth's surface, the acceleration it experiences does not change by much (even if the height of the object is 1000 meters above the earth's surface). As a result, in most cases, we may assume the object experiences a constant downward acceleration of g = 9.81 (m/sec)/sec.


teamonkey(Posted 2005) [#6]
g = GM/(r*r)

Where g is the acceleration due to gravity, M is the mass of the Earth, r is the distance from the centre of the Earth and G is a constant (6.67e-11 if g is in m/s^2, M in kg, r in metres, but it's one of those things you need to fiddle until it looks right in a game. Start with G=1 and scale accordingly).

g=9.81 when r is the distance from the centre of the Earth to the surface.

This equation doesn't hold if you're actually some way under the Earth's surface (because the Earth above you starts to pull you in the opposite direction to the centre)


Filax(Posted 2005) [#7]
Can you post a little and simple example with g = GM/(r*r) formula ?


teamonkey(Posted 2005) [#8]
Try this.

Er, it's actually g = -GM/(r*r). Forgot the minus sign, as usual :)



It creates some planets in random positions around a sun with random velocities. Try fiddling with G and the masses and see what happens. Some of the planets should have sufficient velocity to stay in an orbit around the sun, but those without will crash in to it.


Dreamora(Posted 2005) [#9]
btw: the G is only a "scaling constant" for physical purpose.

So if your forces do not fit in general, this is the best place to start with changing.

if it doesn't fit for single object or part of the system, then its their weight


Filax(Posted 2005) [#10]
Thanks for example :)


Shambler(Posted 2005) [#11]
Also remember that because of friction with the air, objects do not keep accelerating ad infinitum but reach a terminal velocity.


ImaginaryHuman(Posted 2005) [#12]
From Teamonkey's example, it looks like the objects are gradually accelerating faster as they get closer to the sun. So, is gravity supposed to be applied to the acceleration of the object or to the objects position?


Dreamora(Posted 2005) [#13]
Gravity is a force that is applied to an object to it affects which means it accelerates the object -> vector addition to the actual acceleration vector


dynaman(Posted 2005) [#14]
> So, is gravity supposed to be applied to the acceleration of the object or to the objects position?

To the acceleration of the object.

Atmospheric friction would have it reach a maximum value, like Shambler said.


Booticus(Posted 2005) [#15]
Thanks for the example! I was just thinking about that the other day...that I didn't have an example, I mean.


ImaginaryHuman(Posted 2005) [#16]
If the object is moving and it has a velocity, then why would you add the gravity to the acceleration and not to the velocity?


ImaginaryHuman(Posted 2005) [#17]
If the object is moving and it has a velocity, then why would you add the gravity to the acceleration and not to the velocity?


The r0nin(Posted 2005) [#18]
Say Object.x, .y, & .z are position
Object.vx, .vy, & .vz are the velocity.

Let's say that the source of gravity is directly below the object (-y some distance), and is equal to the Earth's gravity at its surface.

You would add whatever movement vectors you have in your routines to vx-vz and then add a -9.8 meters per second to Object.vy to add the gravity.

In other words, gravity is an acceleration because every second you add another -9.8 m/s to the downward velocity. So, with no other force acting upon your object, it will speed up (accelerate) by an additional -9.8 m every second (-9.8m/s at 1 sec, -19.6m/s at 2 sec, etc.). In code, however, you simulate this by adding -9.8 to your velocity each second, even though this is an acceleration.


ImaginaryHuman(Posted 2005) [#19]
How about if you have two large circular bodies representing planets and each has its own gravity and you want free-floating objects in space to be appropriately attracted, so that in the area where the gravitational fields of both planets overlap, some of the gravity cancels each other out?

In that scenario, where you can see things on a big scale, does the pull of gravity need to diminish over distance so, let's say, you don't get any pull if you are half a screen away from the surface?


Who was John Galt?(Posted 2005) [#20]
AngelDaniel - calculate the individual force exerted due to each planet, then add all the xcomponents, all the ycomponents and use these for your acceleration. Do this wherever the player is (not just between planets) and it will give a realistic simulation. This automatically takes care of any cancellation/addition. So yeah, for realistic simulation you keep the diminishing force with distance for every individual body if u want max realism.


The r0nin(Posted 2005) [#21]
If you take a look at the actual gravity equation [g = -G(M/r^2)] you'll notice that the force decreases as the square of the distance. So once you determine the masses of your planets and determine the value of G to suit your simulation (you can use the real value if you want [6.673x10^-11], but to get a large effect you would have to use really large masses... for 9.8 m/s^2 close to one of the planets you would have to use the real value for the mass of the Earth: ~6x10^24 kilograms!), use the given equation and the rest will take care of itself. Calculate the vector pull on object one from planet one, calculate the vector pull on object one from planet two, and at the right distance and location, the vectors will cancel...