2
|
1 var target : Transform;
|
|
2 var damping = 6.0;
|
|
3 var smooth = true;
|
|
4
|
|
5 @script AddComponentMenu("Camera-Control/Smooth Look At")
|
|
6
|
|
7 function LateUpdate () {
|
|
8 if (target) {
|
|
9 if (smooth)
|
|
10 {
|
|
11 // Look at and dampen the rotation
|
|
12 var rotation = Quaternion.LookRotation(target.position - transform.position);
|
|
13 transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
|
|
14 }
|
|
15 else
|
|
16 {
|
|
17 // Just lookat
|
|
18 transform.LookAt(target);
|
|
19 }
|
|
20 }
|
|
21 }
|
|
22
|
|
23 function Start () {
|
|
24 // Make the rigid body not change rotation
|
|
25 if (GetComponent.<Rigidbody>())
|
|
26 GetComponent.<Rigidbody>().freezeRotation = true;
|
|
27 } |