I’m doing a prototype game like Worms and I would like not only to shot, but also see the whole projection curve where my shot will travel before it hit the ground. The only information given by the player is an angle and a power. There is also some level elements like wind and gravity.
Can I have a code for the projection curve? its like a parabola I think. I research about parabola but I had some difficult to apply these math formulas into the programming code.
Thanks.
The math (and physics) part
So this seems like 10th grade physics to me.
The path trced by a projectile is (as you said) a parbola describable by the equation
Now, if you solve this equation, you get the following parameters:
Range:
Height:
(vi = initial velocity, theta i = initial angle of shooting wrt horizontal)
And, the equation in
(x, y)for the parabolic path will be(v0 = initial velocity, theta = firing angle)
The programming part
assuming the following constants:
The sin function is available as
Math.sinThe power function is available as
Math.pow. This means, sine squared will beYou could write the range function as
and the height function as
and the yPosition function as
Note that the angles are in RADIANS
For more information on projectile motion, google it.