Security Camera Rotation

This may seem like a simple question but the unity script reference doesn’t really have a good example of setFromToRotation.

Currently i have a security camera projecting a light on the floor, i want this to rotate between 65 degrees and minus 65 degrees.

so so far what i have is basic:

var rotateSpeed : float = 10;

function update () {
 transform.Rotation(0,Time.deltaTime * rotateSpeed, 0);
}

I have tried fiddling around with something along the lines of

function Update () {

if (transform.Rotation.y <65) {
transform.Rotate(0,Time.deltaTime * rotateSpeed,0);
} else {
transform.Rotate(0,-Time.deltaTime * rotateSpeed,0);
}
}

but that was just a wild stab in the dark and wouldn’t do the job properly even if it did.

I believe the solution is using Quaternion.SetFromToRotation but i don’t understand how to use it properly.

Can anyone help? should be simple enough.

Ok, going through my old questions and resolving them.

iTween is a very good way to do this however isn’t supported when it comes to exporting to Flash (which i am doing)
Alternatively i simply used unities built in animation to make it rotate between two angles at a certain speed and then you can script
to pause the animation when necessary etc.

Thanks for the help guys!

Very old thread but thought I would add this as I spent to long trying to work this out, sorry if the code aint that good as I am fairly new at this but worked great for what I needed.

	public Transform horizontalPivot;
	public float maxPan = 0.0f;
	public float maxTilt = 0.0f;
	public float speed = 2.0f;

	private float panSoFar = 0.0f;
	private bool panBack = false;
	private bool firstRotation = true;

	// Update is called once per frame
	void Update()
	{
		RotateCamera();
	}

	void RotateCamera ()
	{
		if (horizontalPivot && maxPan > 0) {
			if (!panBack) {
				horizontalPivot.Rotate(0, 0, (Time.deltaTime * speed));
				panSoFar += Time.deltaTime * speed;
				if (firstRotation) {
					if (panSoFar >= maxPan) {
						panSoFar = 0;
						panBack = true;
						firstRotation = false;
					}
					return;
				} else {
					if (panSoFar >= maxPan * 2) {
						panSoFar = 0;
						panBack = true;
					}
				}
			} else {
				horizontalPivot.Rotate(0, 0, -(Time.deltaTime * speed));
				panSoFar += Time.deltaTime * speed;

				if (panSoFar >= maxPan * 2) {
					panSoFar = 0;
					panBack = false;
				}
			}
		}
	}

I aint cleaned the code up yet either.

The easiest way is to use iTween. Otherwise use Transform.Rotate, but test against the y value with Transform.eulerAngles instead of transform.Rotation.y.