Mercurial > hg > Game > Games
comparison Chapter5/Assets/SimpleCloudSystem by RM/SceneComponents/Standard Assets/Scripts/Camera Scripts/SmoothLookAt.js @ 2:fdab88fc2cb9
add game projects
author | Yuta ANSE <e135745@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2015 23:14:45 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:347d21cdfc22 | 2:fdab88fc2cb9 |
---|---|
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 } |