# Enemy Rotation to Player

I am beginning to despair.

I want the opponent to turn towards the player ship. Depending on where the player is, the right side of the cannon or the left side should be directed towards the player. So far I’m getting there, but I don’t know how to stop the rotation when the opponent’s side is facing the player.

My Code

` if (Vector3.Dot(transform.right, Cube.transform.position) > 0) { transform.rotation = Quaternion.Euler(new Vector3(transform.position.x, rotatey, transform.position.z)); rotatey -= 1; //Stop it when Player is in 90degrees direction to the right side } else { transform.rotation = Quaternion.Euler(new Vector3(transform.position.x, rotatex, transform.position.z)); rotatex += 1; //Stop it when Player is in 90degrees direction to the left side }`

I Updatet the Code but it doesnt work fine

`
Vector3 directiontoface = (hitCollider.transform.position - transform.position).normalized;
Debug.DrawRay(transform.position, directiontoface, Color.red);

``````            if (Vector3.Dot(transform.right, hitCollider.transform.position) > 0.1F)
{
Debug.DrawRay(transform.position, transform.right, Color.green);

Vector3 posa = new Vector3(0, 0, directiontoface.z);
Vector3 posb = new Vector3(0, 0, transform.right.z);

if (Vector3.Distance(posa, posb) > 0F)
{
transform.rotation = Quaternion.Euler(new Vector3(transform.position.x, rotatex, transform.position.z));
rotatex -= 1;
}

//Debug.Log("Angel face " + directiontoface);
//Debug.Log("Angel right " + transform.right);

//transform.rotation = Quaternion.Euler(new Vector3(transform.position.x, rotatey, transform.position.z));
//rotatey -= 1;
}
else if (Vector3.Dot(-transform.right, hitCollider.transform.position) > 0.1F)
{
Debug.DrawRay(transform.position, -transform.right, Color.green);

Vector3 posa = new Vector3(0, 0, directiontoface.z);
Vector3 posb = new Vector3(0, 0, -transform.right.z);

if (Vector3.Distance(posa, posb) > 0F)
{
transform.rotation = Quaternion.Euler(new Vector3(transform.position.x, rotatey, transform.position.z));
rotatey += 1;
}
}
``````

`