Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

starstriker1

Gravity effects?

This topic is 5584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

One of the items in my game is going to be grav/antigrav beacons. The physics in the game are similar to asteroids and subspace. What I want is for ships to be pulled towards (or pushed away from) the beacons. What algorithim would fit this best?

Share this post


Link to post
Share on other sites
Advertisement
Well, the equation for the force of gravity acting between two objects is F = G*m1*m2/r^2 where G is the universal gravitational constant, m1 and m2 are the masses of the two objects, and r is the deistance between the centers of the two. Basically, this is about all you''re going to need to get a system like this to work.

Oh, and since you''re doing antigravity...

Technically, F = -G*m1*m2/r^2. This negative sign means that the objects are moving towards each other. So for "antigravity", you''d simply not need the negative sign.

Share this post


Link to post
Share on other sites
Well, your anti-gravity beacon would have negative mass.

Four useful formula's G*M1*M2/R^2, G*M1/R^2, G*M1/R and G*M1*R^2. G is the gravitational constant and most generally M1 is the mass of the earth and R is its radius. When that is the values then G*M1/R^2 is the acceleration due to gravity, i.e. little g. m*g=G*M1*M2/R^2 is your weight. m*g*h is roughly the work required to raise a mass m a height h above the surface of the earth. It is exactly (G*M1*M2*(R+h)/(R+h)^2-G*M1*M2*R/R^2)=(G*M1*M2/(R+h)-G*M1*M2/R) which is roughly G*M1*M2*h/R^2 since (R+h)^2 is roughly R^2. If (R+h)^2 was not roughly equivalent to R^2 then you would need a function which would be f(R)=G*M1/R instead of a constant. Then the change in potential energy would be m*(f(R+h)-f(R)). Perhaps not that handy, but with an electric fields f gives your voltage and f(R+h)-f(R) is the differance in voltage between two locations.

That is the basics. Now there are relationships beyond the obvious here. The force exerted by a graviational field upon a mass is towards lower potential energy. For a fixed mass that is a lower potential. The graviational field is minus the gradiant of the potential. Using a weather map as a analogy it is the little arrows showing you which way and how strongly the wind is blowing. The contour lines showing air pressure is the potential. Air flows form high pressure to low pressure. The wind blows in the direction that the air pressure decreases most rapidly. The gradiant of a function giving air pressure would be towards the most rapid increase in pressure. So the potential is minus the gradiant of the field.

Now in generally when you deal with gravity you are either dealing with the special case of gravity at or near the surface of the earth or you are dealing with incredibly massive objects. Most of those massive objects are round objects. That makes them work pretty much as a point mass. Electric charges are distrubuted in all kinds of fascinating and interest shapes. An infinite plane charged plate produces a uniform field. The force is the same everywhere. Of course can't have an infinite plane conductor, but you can be close enough to a finite plane that it might as well be infinite. Line chares, i.e. straight wires, drop of linearly rather than the square as with a point charge. That is due to the components of the force parallel to the line cancel one another out.

The calculations could get really nasty. A lot easier is to just precalculate the field vectors. You can have them at the corners of a square or grid and interpolate to get a specific point. If they are few and far between you can use some type of subdivision. Close to a generator the grid is very dense and further away more sparse. Assuming you use point generators they are going to drop off according to the square of the distance so you only need one quarter as many per unit volume as your distance away doubles to get the same level of accuracy. I could be wrong, but I don't believe it is an eighth as the volume would be because your volume has nothing to do with it. It is just the straight line distance from the center.

Also worth noting is that if the generators are not points or spheres you cannot use a center of gravity. I believe the only reason you can use centers of gravity on the earth is that the relative masses and displacements are so large that you are effectively in a uniform field. Your mass does not significantly alter the gravitational field and it pretty much points the same direction over the range you are moving. I could be wrong about that, but I am quite certain that with charges you cannot replace them with an equivalent point charge except in the special case of a sphere. That is because it is symetric in all directions.

[edited by - LilBudyWizer on February 7, 2003 2:43:48 PM]

[edited by - LilBudyWizer on February 7, 2003 2:48:35 PM]

Share this post


Link to post
Share on other sites
Sorry, I have a test in electro-statics so it was a chance to review.

Basically you can view each beacon has producing an acceleration towards or away from it depending upon how far the ship is away. That acceleration is a vector. So you give a beacon a positive or negative number. You then divide that number by the square of the distance from the ship which is more accurate but also saves you a square root to find the distance. You then multiply a unit vector pointing from the ship to the beacon by that number and that is your acceleration vector. You sum the vectors for the individual beacons to get a resultant vector. You also add in any acceleration due to thrusters or whatever. That is a change in velocity per unit time so you have to scale it by the actual time delta.

Your ship has a velocity vector at the start of the frame. By the end of will change by the scaled acceleration. So you will roughly travel a distance of the average of those two velocities times your time. You add that vector to your ships position and that is where you move to during this frame. Not terribly accurate on a highly curved path, but good enough since you are dealing with very small time intervals.

Share this post


Link to post
Share on other sites
Ok, I''ll try that. First though... I''ll have to decipher what you have there... it looks good, but theres just so much stuff there that I''m getting confused :\

I should have probably given you a link to what I have of my game. Its not near complete... in fact, I have a version thats twice as good sitting on my hard drive (and its been made that way over a couple days... wow...). Anyways, the link is www.geocities.com/momogames/deltawing.zip

Instructions and known bugs are included in the readme.

I hope that''ll give you a better understanding of what I want... it probably won''t, but you can''t blame me for trying.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!