1
General / Re: Feedback on my projectile trajectory model.
« on: December 07, 2016, 02:46:30 pm »
Thanks for the input, i edited the main equation so that it uses initial "power" and angle instead:
Angle and power are adjusted using the arrow keys. The trajectory now looks kind of good except for one thing. The "speed" of the shoot is only affected by travel distance in x. So when shooting with an angle close to 90 (straight up) the shoot moves extremely fast where as when i shoot with an angle close to and above 0 it moves extremely slow.
if (shoot) {
x += elapsed*800;
y = x*tan(angle*PI/180) - (g * pow(x, 2)) / (2 * pow(power, 2) * pow(cos(angle*PI / 180), 2));
player.setPosition(200+x, window.getSize().y - y-200);
if (player.getPosition().y > window.getSize().y) {
cout << player.getPosition().x << endl;
player.setPosition(200, window.getSize().y-200);
x = 0;
shoot = false;
}
}
x += elapsed*800;
y = x*tan(angle*PI/180) - (g * pow(x, 2)) / (2 * pow(power, 2) * pow(cos(angle*PI / 180), 2));
player.setPosition(200+x, window.getSize().y - y-200);
if (player.getPosition().y > window.getSize().y) {
cout << player.getPosition().x << endl;
player.setPosition(200, window.getSize().y-200);
x = 0;
shoot = false;
}
}
Angle and power are adjusted using the arrow keys. The trajectory now looks kind of good except for one thing. The "speed" of the shoot is only affected by travel distance in x. So when shooting with an angle close to 90 (straight up) the shoot moves extremely fast where as when i shoot with an angle close to and above 0 it moves extremely slow.