Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

Thank you for your time.

share|improve this question
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. – Blue May 14 '13 at 8:22
up vote 2 down vote accepted

As Almo's comment mentions, your last paragraph is a pretty solid approach to the problem.

If you'd like one that requires less calculation however, another solution (provided you already have a method to hit a stationary target with a mortar shell) is to launch at and store the target's position in the world. Then, while the shell is in the air, make the shell's position equal to the position of the shell along the original arc plus the difference between the enemy's current position and the position when you launched.

This method means you don't need to know where the character is going to go as even if a player or random number generator was controlling the unit it will still hit with 100% accuracy (though it might look like the shell is cheating if the enemy attempts to quickly dodge and has high speed)

share|improve this answer
Just to make sure I understand :) I add the X,Y of the enemy coordinate to the curved path of the shell on each update so the entire curve moves with the enemy? Meaning I only have to calculate the curve on the enemies position initially as it fires... This seems interesting and I will try this out as well to compare effects. +1 – Blue May 14 '13 at 8:25
@Blue Yep, that's pretty much it. That means when the shell lands it will always land on the point of where the enemy started + the distance to where the enemy currently is (exactly on the enemy). Since anyone looking will only see the shell (essentially a point) and not the whole arc, the effect shouldn't be too noticeable. Also as a side note, this method would work just as well if you also had to deal with Z in your path. – Lunin May 14 '13 at 17:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.