I'm just starting with game development and some physics related to that. Basically I want to calculate a trajectory given an initial velocity and as well as an elevation / angle. So I wrote this code in Java (I left out some class related code and such):
int v0 = 30; // m/s int angle = 60; double dt = 0.5; // s double vx = v0 * Math.cos(Math.PI / 180 * angle); double vy = v0 * Math.sin(Math.PI / 180 * angle); double posx = 1; // m double posy = 1; // m double time = 0; // s while(posy > 0) { posx += vx * dt; posy += vy * dt; time += dt; // change speed in y vy -= 9.82 * dt; // gravity } This seems to work fine. However, is there a better way to do this? Also, is it possible to scale so that 5 meter (in calculation) corresponds to 1 m for the posx and posy variables?
Thanks in advance!