Hello, So I have a tank “3D”, and I want it to “Shoot” only when the Cannon is Facing the target. Now I am using Vectir3.Angle, and it seems to work but its not perfect. because I am only Interested in the Horizontal Angle Not the Vertical, nor an average of the two. Please help me solve this. I am a total noob here. Thank you in advance!
Vector3 dir = target.position - transform.position;
float angle = Vector3.Angle(dir, transform.forward);
if (angle < angleValueToStartFire)
{
if (fireCountdown <= 0f)
{
Shoot();
fireCountdown = 1f / fireRate;
}
fireCountdown -= Time.deltaTime;
}