How to simulate gravity with multiple thrusts

I need a bit of logic help here. I'm working with a program to simulate gravity. the equation for gravity is v=gt+v* or the current velocity is equal to gravity times the time elapsed plus the initial thrust's velocity. With the program I'm working with, gravity is 0.1 pixel per frame, and the upward thrust is 0.3 pixels per frame. I figured out the velocity for a single thrust would be something like:

1
2
  for(frame = 0; frame < 4; frame++)
      velocity.y = -0.1*frame + 0.3;


but what if there is another upward thrust before the first one has finished? ie. if they do a second thrust one frame after the first, then the velocity would need to be added together, but I cannot figure out how to do that!
From your code snippet, I assume that a single "thrust" is a force of 0.3 that lasts for 4 frames? And you want to know what happens if another force input occurs within those 4 frames? Assuming that the forces don't add, then maybe you could just reset the counter:

1
2
3
4
5
6
for (int frame = 0; frame < 4; ++frame)
{
    update(v);
    if (thurst_input())
        frame = 0;
}

be careful.
velocity vectors are what you need, not just velocity as a value. And thrust is a force, which uses different but related equations. This sounds like a 'stop coding and solve it on paper' issue. You can't code it until you do the math on the side and figure out what it is you need to code up.
Topic archived. No new replies allowed.