Look At Player with Clamping.

Okay, I think I might be a little tired, cause I cannot even begin to work this out. I am almost positive there is a simple solution to this, but I cannot think of what it is.

In my current project, I have an Enemy that always look towards the player with a raycast. as closely as it can. It should however only be able to turn a max of 45 degrees from directly forward.

I think it could be done by casting a ray a long the objects forward vector while rotating the object itself back and forth. How would I get the object to turn as close as it can to the player without rotating beyond 45 degrees in either direction of forward

You can clamp the euler angle rotation of the enemy game object. Can’t you?

 // Rotate towards player

// Make sure enemy's rotation is clamped between -45 and 45 degrees
enemy.transform.eulerAngles = new Vector3
     Mathf.Clamp(enemy.transform.eulerAngles.y, -45, 45),