Hello Stack Exchangers!
I'm developing a video game. One feature requires an archer be able to target an enemy and shoot an arrow at it. I've looked around and found plenty of guides on how to do this with the quadratic formula with the appropriate variables and am receiving what I believe to be the correct output, but the arrow trajectory isn't what it should be (it doesn't hit the enemy). Here is what I have (with a sample of values taken from the program).
Origin of the shot (608,-352);
Target of the shot (1280, -705);
x = 672;
y = -353;
g = -275 (this is what I'm using for gravity);
v = 1000; (The velocity the arrow is shot at);
setting up the variables:
a = $.5g(x/v)^2 = -62.0928$
b = $x = 672$
c = $.5g(x/v)^2+y = -415.0928$
$ angle 1 = atan(\cfrac{-b + \sqrt {b^2 - 4ac}}{2a}) = 0.5817$
$ angle 2 = atan(\cfrac{-b - \sqrt {b^2 - 4ac}}{2a}) = 1.4727$ Then in order to get the individual X/Y velocities from that angle (which I believe is in radians):
For Angle 1 $v_x = v cos \theta = 835.50$
$v_y = v sin \theta = 549.48$
For Angle 2 $v_x = v cos \theta = 97.90$
$v_y = v sin \theta = 995.19$
Unfortunately, the arrow doesn't arc through the target location. The second angle (from the - part of the quadratic equation) doesn't fare any better.
Any help out there?