I want to make a box "fly" so while user press D it's add thrust then on A it decrese untill 0, W and S control the direction of my box.
I have problems after I add the gravity to update correctly my X and Y position. My actual code is like this: (I'm using gamemaker but it's same as other languages, came execute 60 frames per second)
frametime = delta_time / 1000000; spd = sqrt(power(velx ,2)+power(vely ,2)); tempgy = g * frametime ; //tempay = ((thrust / m) * 32) * frametime; // or my box procede diagonally offcurse tempax = ((thrust / m) * 32) * frametime; y -= (vely + tempgy/2 + tempay/2 ) * frametime ; x += (velx + tempax/2 ) * frametime ; vely += tempgy + tempay; velx += tempax ;
m is mass of object = 500
g = 9.81
32 it's pixel per meter
So, basically I calculate the acceleration on gravity, and need to apply acceleration to
y based on direction if I not understand wrong. So for the
X component of thrust I have to multiply
sin(degtorad(dir)) and for the
Y must multiply
cos(degtorad(dir)), but I have to apply the
cos only on acceleration?
I think I am doing it wrong because if I use
g=0 and just using thrust my box act not as intended (ex: If I try to do a loop and stop accelerating my box will not follow the loop direction but continue on straight line)
Sorry for the stupid question but I really not know how to fix it. I see lot of tutorials with vectors but it's not supported here so can't use them. Thank you and best regards.