- Home /
how do i calculate the angle to fire a bullet to intercect
i have been doing a tower defence game. and came accross a problem that i can not solve
in 2d terms i have a enemy at 0,0 moving eastwards at 20 miles per hour
the tower is south of the enemy by 30 miles and the bullet travels at 90 miles per hour.
i need to figure out what angle or vector i need the tower to be facing for the bullet to hit the target .
i have been told that i might need to use quadratic equations , but i still cant figure it out . is there any good links on how to do the calculations
to be honest there would be a lot to be said for asking this on a general site like stackexchange.com or math-stackexchange or even gamedev or some handy high scool physics site you know?
t is really not a Unity3D question.
you need look no further than wikipedia for vast reference on this
http://en.wikipedia.org/wiki/Trajectory_of_a_projectile
scroll down for every equation. use google to find 100s of superb explanations of this !! hope it helps
to be clear there is nothing at all in the Unity APIs that is relevant to this. it's just an everyday math problem
Answer by Owen-Reynolds · Sep 20, 2012 at 02:56 PM
If you look, tower defense games don't lead targets. Bullets go fast enough and are wide enough they don't need to lead, or they are guided.
But, a very cheap way to do it is to find flightTime=targDist/bulletSpeed. Then lead the target by that much: aimPos=targPos+targMovePerSec*flightTime. That's not quite right, since time to the new target is different, but close enough most of the time.
I do something similar to this sometimes. Just keep repeating the process; calculating the flight time to each aimPos gives you a more accurate number each time. In my case I used two iterations and it worked for a good number of ranges.
Your answer
Follow this Question
Related Questions
How can I detect if 3 cubes are in a line close to each other like tetris? 1 Answer
Making enemy ship fire. 1 Answer
Check if a vector is close to a mesh 1 Answer
change the length of the vector 1 Answer
Vector 2 3 4 help 1 Answer