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);