- Home /
Problem is not reproducible or outdated
AI Turret Aiming
Hey guys, I'm making a naval game with shore batteries that will fire upon the player. I have looked at other posts and scripts involving target lead and parabolic trajectories, but all I need is a script that allows my turret to aim higher to account for shell drop and lead the target. Any ideas?
Thanks!
ps. My projectiles and targets are rigidbodies.
[EDIT:] I am now intending to fire shells in a parabolic path.
Hi, sorry for te question but what do you mean with “aim higher to account for shell drops and lead the target”? And is it a 2D or 3D game?
Oh, it's a 3D game. The shells will drop by a constant amount per second, and I was wondering if I could have the guns aim higher depending on the shell drop relative to the distance to the target.
Answer by andrew-lukasik · Jun 05, 2018 at 07:51 PM
//linear drop:
aimPosition = targetPosition + Vector.up * distanceToTarget * dropRate;
//non-linear drop:
aimPosition = targetPosition + Vector.up * dropCurve.Evaluate( distanceToTarget );
Thanks, but my shell drop is relative to time, not distance. How could I use this code?
Thanks for the answer, but what is dropCurve?
Also, this Vector.up, is a direction to compensate gravity alone but you can use arbitrary directions to, for example, compensate for wind blowing etc. Or summarize these and compensate for many such influences.
Oh I'm only having drop affect the shell, no other factors like wind. (Sorry for the late reply, was busy with exams)
Answer by andrew-lukasik · Jun 16, 2018 at 07:03 AM
Check out this repo: https://github.com/IronWarrior/ProjectileShooting/blob/master/Assets/Scripts/ProjectileMath.cs
I've actually found another similar script which performs extremely well, but this script could be extremely useful to others, and I thank you for that. Thanks for your time! (also maybe move that link into your answer)
Follow this Question
Related Questions
Turret Movement 1 Answer
Shell Drop and Aiming 1 Answer
AI rigidboy aiming 0 Answers
Autoaiming Turret Cannon? 3 Answers
Turrets |Aiming don't work 1 Answer