- Home /
How To Calculate Speed For Projectile Based On Target Distance And Height
Vector math is not my strong suit, and would really appreciate some help trying to automatically calculate the speed of a projectile that I want to follow a parabola arch towards the player like this:
This is going to be setup on an enemy AI; I have a method that can calculate the horizontal distance and then sets a random value for height so there is a random element to the projectile, but I can't find a way to calculate how fast the projectile will need to move in order to land on the designated target based on the random height element I want to add to this. Ideally, I want this attack to be timed, so that the time value will be constant in how long the projectile needs to travel, but as mentioned need help finetuning the speed value so it doesn't fly too far away from the target or not far enough.
Is there anyone who has solved for this or understands this type of math well enough to steer me in the right direction?
Thanks!
Answer by Eno-Khaon · Dec 21, 2020 at 10:53 PM
I'm going to be a little lazy on this and simply redirect you to a previous answer I've given on this subject.
Incidentally, a Time factor is the one that will guarantee that the target can be reached (whereas a fixed angle can fall beneath the target and a low launch speed can similarly fall short). Just make sure you balance things out right that you don't wind up with an unnecessarily/unnaturally high or low arc in the trajectory.
Link url: https://answers.unity.com/questions/1087568/3d-trajectory-prediction.html
Thanks for the quick response; the solution that calcuates A-B based on time appears to be exactly what I'm looking for, I will double check probably tomorrow to see if it handles what I was trying to do.
Also want to say your Guardian Legend icon is cool! Super underrated NES gem with probably the consoles best music.
Thanks again!