Thursday, March 10, 2016

physics - 2D Planet Gravity


I'm trying to make a simple game where a spaceship is launched and then its path is effected by the gravity of planets.


Similar to this game: http://sciencenetlinks.com/interactives/gravity.html


I wish to know how to replicate the effect the planets have on the spaceship in this game so a spaceship can 'loop' around a planet to change direction.


I have managed to achieve some bogus results where the spaceship loops in a huge ellipse around the planet or is only slightly affected by the gravity of a planet using Vectors.


Thanks in advance.


p.s I have plenty of coding experience just none to do with game dev.



Answer




In your case there is an spaceship, which moves affected by the gravity of all the planets. Each planet applies force equal to 'm1*m2/ r^2' in which m1 and m2 represent masses of spaceship and planet, and r is equal to euclidean distance of planet and space ship. you just have to calculate sum of all the forces applied to ship. from the rules of newton we know 'f = m*a' where f is total force applied to an object, m is it's mass and a is it's acceleration. from this point you can read this page to learn how to use acceleration to compute velocity and position over time.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...