Implementing Full Gravity - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Design (/forum-5.html)
+--- Thread: Implementing Full Gravity (/thread-7582.html)
Implementing Full Gravity - Justin Brimm - Sep 5, 2002 04:17 PM
Does anyone have any examples, tutorials, or even a full write-up of how to implement gravity, and everything that can affect it (essentially recreating real-world gravity)?
So far, I've found the equation that deals with the force of gravity
Implementing Full Gravity - Baldock - Sep 5, 2002 04:40 PM
If you are talking in a 2D world just apply a 9.8metres per sec accelerating vector down.
However when you say it doesn't work what sort of results are you getting? you'd have to remember that the earth is massive compaired to objects on it which are close so it has some force. If you are giving 3d objects little mass and putting a fair about of space between them and expecting gravity to do much that might be a problem.
Implementing Full Gravity - w_reade - Sep 5, 2002 09:03 PM
Proper gravity only really has a place in space games. If that's what you are doing:
The gravitational force one object exerts upon another is indeed given by the formula you quote.
To get the total gravitational force vector on a given object (theObject), you need to sum the forces of each object that exerts a pull. To get the force vector exerted by someObject:
* calculate a unit vector pointing from theObject to someObject.
* calculate the gravitational force using your formula.
* multiply the two together.
As you go through the other objects in the scene, add their contributions to a running total, and then apply the total force to the object in question.
Please note that the above is crying out for optimisation. Two main things:
1: it's probably faster to calculate the gravitational field at the point, since one doesn't have to worry about the affected object's mass at any point, and
2: you certainly don't want to bother summing the contributions of individual spaceships, unless they're very very massy spacecraft very close to one another indeed. I'd suggest some cutoff point, at a large number of kilograms (say 10,000,000Ö at least), where anything massing less is not considered in the calculations.
hope this helps - otherwise try an A-level physics text.