# Aim prediction along a parabola - How to make a Tower Defence Mortar aim accurately

I am building a very basic tower defence game in Unity3D where one tower is your standard long range mortar/artillery.

I want the projectile it fires to follow a parabola curve to make its movement seem like a mortar. This movement is not dependant on any physics (as I can make a projectile follow a curve but I could implement the Unity3D physics if the method used would benefit from it.

My question is: What technique should I use to ensure the projectile hits the locked unit whilst taking into account that the unit is moving along a possibly non linear path (defined with my A* implementation.) I have not implemented any code as of yet as I wanted to consult the masses for any wisdom you can provide!

My initial idea was to fix the time the projectile would take along its parabola curve (regardless of distance) and try and track the position the unit would be at after this time delay. Is this along the right lines or are there alternative methods to consider when aiming a projectile that follows a curved path instead of a linear one?

• Your last paragraph looks reasonable to me. – Almo May 13 '13 at 13:53
• I agree, the last parahraph sounds great, though you can calculate on what point the projectile would hit the unit based on the speed of both. Example: the unit and the rocket move x units every instance of time T (defined by your game loop). You can then calculate where the unit will be on T +1. You can then calculate if the rocket can reach this point based on the distance it needs to travel (distance calucation using pythagorian formula) (your rocket has a set speed: 2 points each T for example). If the distance < this speed * T this is your rocket endpoint. Else, calculate T + 2 etc. – Thomas May 13 '13 at 15:15
• I forgot to mention, your rocket also has a splash radius i presume, if you cannot find the point where the rocket wil actually hit the target, you could calculate if the unit will be in its AoE radius. Then you could use this coords as you rocket target. – Thomas May 13 '13 at 15:20
• Your other option could be to treat it like other projectiles in your game. But instead of making it a straight line you use a formula for the arc. IE: y = -(x-x/2)^2 + b + c where y is the height, x is distance to target, b is the maximum height of the projectile and c is the vertical position of the tower. EDIT: unless of course your other projectiles arrive instantly... – UnderscoreZero May 13 '13 at 15:48
• @UnderscoreZero - They are not all instant projectiles but I have functionallity built for both types. I have isntant hit raycasted lasers and proijectile hit box style bullets/rockets. The mortars will fall under the hit box type. – Tom 'Blue' Piddock May 14 '13 at 8:22