Skip to main content
gamedev.net
🔒 Locked

Space objects pulled toward planets

Started by Andos 0 replies 300+ views
Original Post
Andos
Andos
I once saw a game on the net where you had to shoot an object with a angle and speed. There were lots of "lanets" in the level that pulled the object towards it. The hwole point was to use the gravity to get the object into a little spaceship. How can i calculate the objects speed and angle if i have the position and mass of the planets... (the object whont be affected so much of a planets gravity if it''s far away from it...)
BeanDog
BeanDog
You don''t calculate the speed and direction based on distance from the planets; you calculate its acceleration. Remember:
Vx(new) = vx(old) + a*time
X(new) = X(old) + Vx(old)*time + .5f*a*time*time

And for gravitation,

a = G*M/(r*r)
(before anyone complains it''s actually F=, notice I divided both sides by m already)

Where a = acceleration, G = universal gravitational constant (look up in a physics textbook or just make one up that works good), M = mass of planet, r = distance from ship to center of planet.



~BenDilts( void );

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.