Stop player looking at object (freeze rotation)

Hi there, so I have a door at the end of a hallway, and I want the player to be able to begin to look at its general direction, but as soon as it comes within a certain limit (to be able to see the hallway itself) I am trying to get the roation to freeze; as though even if you want to look at that door, and down that corridor, you can’t.

I have a box collider set up that follows the player’s movement on the X axis, so up and down the corridor, and then tried to set a camera rotation from a raycast but it’s not right.

If anyone has any suggestions on where to possible start with an idea like this I would be very grateful for support.

Thank you