How would i be able to make that when
renderer.isVisible my camera rotates to look at the
object and the more i look at the faster and stronger the
camera rotates?
You can use the angle between the forward of the camera and the direction of the object to modify the rotation speed.
#pragma strict
var target : GameObject;
var minSpeed = 3.0; // Degrees per second;
var maxSpeed = 30.0;
private var maxAngle : float;
function Start() {
// Generates an approximation of the max angle since isVisible
// will return true when the pivot is not visible.
var ray = Camera.main.ViewportPointToRay(Vector2(-.1, -.1));
maxAngle = Vector3.Angle(Camera.main.transform.forward, ray.direction);
}
function Update () {
if (target.renderer.isVisible) {
var toTarget = target.transform.position - transform.position;
var q = Quaternion.LookRotation(toTarget);
var angle = Vector3.Angle(Camera.main.transform.forward, toTarget);
var factor = 1.0 - Mathf.Clamp01(angle/maxAngle);
var speed = minSpeed + (maxSpeed - minSpeed) * factor;
transform.rotation = Quaternion.RotateTowards(transform.rotation, q, speed * Time.deltaTime);
}
}