# Enemy Rotating Towards Player

I’m making an arena game with zombies and I’m using this
transform.LookAt(Player.transform);
to make the enemy look at the player.
The problem with this is that the player cant gets behind the enemy which is a key part of the game. I was thinking of making the enemy slowly turn toward the players position but I can’t find how to do that.
Any help would be very much appreciated.

You can make an empty game object that sets it’s position to the player every so often, then make the enemy look at the game object instead

Hey @geffengilbert, so there are a few ways you can do this. I’m hardly an expert but there are two decent ways that jump to mind. One simple way is to use physics with torque, mass and drag, but that depends a bit on your set up. If you can use physics you can use something along the lines of:

``````public class LookAt : MonoBehaviour
{
public GameObject target;
public Rigidbody self;
public float turnForce;

void FixedUpdate()
{
Vector3 targetDelta = target.transform.position - transform.position;
float angleToTarget = Vector3.Angle(transform.forward, targetDelta);
Vector3 turnAxis = Vector3.Cross(transform.forward, targetDelta);

}
}
``````

Then you can adjust the movement by playing around with the mass of the enemy and the turnForce variable. Alternatively if physics isn’t an option you can go with using transform.RotateAround():

``````public class LookAt : MonoBehaviour
{
public GameObject target;
public float turnRate;

void Update()
{
Vector3 targetDelta = target.transform.position - transform.position;
float angleToTarget = Vector3.Angle(transform.forward, targetDelta);
Vector3 turnAxis = Vector3.Cross(transform.forward, targetDelta);

transform.RotateAround(transform.position, turnAxis, Time.deltaTime * turnRate * angleToTarget);
}
}
``````

Here you’ll you need to play around with the turnRate and might want to clamp the angleToTarget variable to get things right.

Dude i also used this code piece and will you tell how to add a clamp to x, y, z of rotation pls?