Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualJTippetts

Posted 10 October 2012 - 07:54 PM

Some time back, there was another discussion about this topic:

http://www.gamedev.n...ng-their-shots/

FLeBlanc runs through the math to calculate the point you need to aim at using a quadratic equation, assuming there is a point you can aim at that will possibly hit the target. Note that sometimes there just is no solution.

Edit:
Eh, just re-read and noticed you want tracking bullets, rather than target leading. In this case, it becomes a sort of tradeoff. How tightly do you want them to track? The way you have it currently, you calculate a trajectory for the bullet based on the vector from the tower to the enemy, but then you add this vector to the existing velocity vector. This will give you an accurate heading initially, but as the trajectory diverges away from a straight line the new velocity vector has a harder and harder time trying to correct out the old, now-incorrect velocity with the new heading, so the bullet just goes more and more awry.

If you want the bullet to tightly follow the enemy, then each update just replace the old trajectory with the newly calculate trajectory. However, this could result in some pretty tight curves. If you want to limit the curves, then you can calculate some vector that lies in between the old velocity and the new velocity whose angle relative to the original velocity is no greater than some limit, A. Then set the velocity to this new vector. This way, the bullet will loop around and eventually spiral in on the target, without sudden and drastic changes in direction.

#1JTippetts

Posted 10 October 2012 - 07:46 PM

Some time back, there was another discussion about this topic:

http://www.gamedev.net/topic/614147-enemies-leading-their-shots/

FLeBlanc runs through the math to calculate the point you need to aim at using a quadratic equation, assuming there is a point you can aim at that will possibly hit the target. Note that sometimes there just is no solution.

PARTNERS