Search code examples
physicsgame-physicselm

how to do physics for space war?


I am trying to do a basic version of space war(http://en.wikipedia.org/wiki/Spacewar_%28video_game%29) but I cannot figure out how to do the inertia part

that is my code : I should let the ship accelerate or slow down based on where it faces

model is the ship vx and vy are velocity of x and y direction theta are rotate degree 20 is for make it move slow

 vx=model.vx+(cos (degrees model.theta))/20,
 vy=model.vy+(sin (degrees model.theta))/20

but it does not seem right Can someone help me? I am horrible in physics!


Solution

  • A very accurate and efficient integration is to compute: PosNext = 2 * PosCurrent - PosPrevious + Acceleration*Timestep^2

    It is called Verlet integration scheme. For Velocities you just update by: VelocityNext = (PosNext-PosCurrent)/TimeStep.

    You can use your sine and cosine with the acceleration constant. Euler forward is not very accurate, try to avoid it.