- Home /
Top down shooter trajectory
Hey guys im currently working on a top down shooter type game where the player is a tank. So far i have the tank turrent rotating around and looking at the mouse position. I am currently trying to get my projectile scripting started and i am drawing blanks at where to start as i am new to programming. What i want is a way to make the projectiles trajectory path set to where it will collide with the ground at the point where the cursor was when the player shot the projectile. So in other words i want the tank projectile to land where the players cursor was when they shot the cannon. Also how would i go about making a min/max range for it aswell so the cannon will not fire right beside the tank. Thanks in advanced for your help and im not asking for anyone to write out all the code for me but jus something to get me started in the right direction!
Also forgot to mention the game is always going to be on a flat plane if that is relavent
Answer by Thelo · Nov 16, 2010 at 09:56 AM
There are many possible correct trajectories from a launch point to a target, depending on angle, initial velocity, and whether you choose a high or low trajectory.
For instance, you might choose to always shoot the projectile at the same initial angle, say 45 vertically, and vary the projectile's initial velocity to determine how far it goes. If you want a min / max range for the cannon with that solution, that means you could set a min / max to that initial velocity, or refuse to fire altogether if the target is too close or too far.
Another possibility is to fix the initial velocity, but change the firing vertical angle to determine how far the projectile goes, with 45 going the farthest. With this solution, the "feel" of the projectile leaving the cannon is more constant, since it always leaves at the same speed. Outside of the maximum distance shot (45), there are always two possible angles that will land at the same target - for instance, a 30 shot and a 60 shot, fired at the same initial velocity and without any air resistance, wind, or obstacles, will land at the same spot, but the low angle shot will land faster than the high angle shot will. You can decide to always use the low shot so the projectile lands faster, or use the high shot to better avoid ground-based obstacles, it's up to you.
If you want a min range for the cannon with that solution, you could set min / max shot angles. The max range will be what the range is when firing at 45.
You can find the relevant equations here:
Thank you tehlo for the very usefull information =D i will look into that asap.