Right so i have an Enemy Prefab with a hierarchy something like this
Enemy
| -Rotate Point
|-Gun
|-FirePoint
The aim is to have the gun point at the player and follow it as the player moves.
The Rotate point is there so the Gun GameObject rotates around a certain point to making it look more natural.
I currently have the script attached to the RotatePoint GameObject in the heirachy :
void Update()
{
Vector3 difference = new Vector3(GameObject.FindGameObjectWithTag("Plane").transform.position.x, GameObject.FindGameObjectWithTag("Plane").transform.position.y, 0);
difference.Normalize();
float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset);
}
The gun currently does sort of track the player but is very slow in doing so and occasionally enemies will spawn firing way off from the player see screenshot.
Just trying to find a method that tracks the player smoother and more accurately than my current method. Any help would be greatly appreciated.