AI target prediction for turret

Hi. I have a script that based on the rigidbody.velocity does a prefire from turret, (shoots where the target is going to be). It takes Vector3 target.transform.position and adds to it certain value, based on the velocity of the target.
My problem is that this is not an universal solution for many things like distance from the target, velocity of target, the bullet speed and drag applied to the target.

I thought of a different approach to this “AI”. What if I changed the target, based just on the x y z values of the enemy ship ? It would be like a circle floating on either right or left side of the enemy ship. (Many modern games have this implemented, where the AI tells you where to shoot, to hit the target.). Do you happen to know how to implement this ? Thanks.

This game is top down.
Here is my code that I currently use.

rb = target.GetComponent<Rigidbody>();
Vector3 targetMovePerSec = rb.velocity;
Vector3 estHitPos = target.transform.position + targetMovePerSec;

Vector3 diff = estHitPos;

diff.Normalize();
float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;

transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0f, 0f, rot_z), Time.deltaTime * SpeedOfRotatingWhenShooting);

And what about add a chance to fail, instead try to read when it will be?, so it would be the same at eye, if a Random.Range its less than 50, then you add an offset of the bullet final target.

(and it would seems cooler if you ask me, some kind of real aiming and not a linear one)

Its a lot more easy, for both of you, the computer and the programmer :slight_smile:

am i a genius? :stuck_out_tongue: cause i nailed it

Thank you for your effort but you have completely missed the point of my question.

I tried this code it misses everytime

Please don’t necropost on the forums.

Thanks.