I found a really basic script on the Unity website for making an object to aim at another object. It will aim at the object no matter where it goes so is it possible to limit the rotation of the camera so it can only rotate in between 2 numbers of rotation?

Here’s the code

var target : Transform;
function Update (){
    transform.LookAt(target);
}

For a better understanding what I’m doing is making a static camera sit in a room and aim at the player then when the player goes to another room it switches to a new camera, but my problem is if my character goes into certain areas the camera can bug out a little bit by trying to aim when I don’t want it to aim, I just want to be able to limit where the camera is aiming at.

Couple ideas:

  1. Make some ‘dummy’ targets (empty game objects) and place there where you want the camera to look. Then look at those (instead of the player) depending on where the player is. You can set up some Collider objects (isTrigger) and use the OnColliderEnter method to trigger your camera movement.

  2. Look at the Y component of localEulerAngles and set it to specific values depending on what it currently is. Like

    if (localEulerAngles.y > 15 && localEulerAngles.y < 50)
    localEulerAngles.y = 40;

or something like that