Turret Field of View?

I’m developing a space combat based game and can’t figure out how to make the turrets aim at a target, but only when they are in its field of view. Yes, I have looked around and could not find anything the same as what I’m looking for.

So say I have a turret on both the top and bottom of a ship and I want the viewing angle to be 200 degrees horizontally. When an enemy is withing that 200 degree angle I want the turret to look at the enemy. The later mentioned is simple, but I can’t understand a way to get a viewing angle. Thanks for the help in advance!

Hey there, if you get the direction from the weapon to the target you can use that to get a rotation, something like this…

Vector3 targetDirection = (weapon.transform.position - currentTarget.transform.position).normalized;

Quaternion rotationToTarget = Quaternion.LookRotation(targetDirection);

Then you just need to clamp this rotation to your desired limits.

Hope this helps.