I have this enemy the rotates around in a circle, and I want him to fire at the player only when he’s directly pointed at him.
But I’m having a hard time getting the target angle that the enemy needs to fire at. Here’s the code I have that’s trying to
get the angle between the enemy and the player:
GameObject player = GameObject.FindGameObjectWithTag ("Player");
Vector3 playerPos = player.transform.position;
Quaternion targetRotation = Quaternion.LookRotation (Vector3.forward, playerPos - transform.position);
It compiles right, but it doesn’t seem to shoot at the right spot. And it doesn’t always shoot every full rotation.
Any help would be greatly appreciated.