Mercurial > hg > Game > Games
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Chapter5/Assets/SimpleCloudSystem by RM/SceneComponents/Standard Assets/Scripts/Camera Scripts/SmoothLookAt.js Fri Jul 17 23:14:45 2015 +0900 @@ -0,0 +1,27 @@ +var target : Transform; +var damping = 6.0; +var smooth = true; + +@script AddComponentMenu("Camera-Control/Smooth Look At") + +function LateUpdate () { + if (target) { + if (smooth) + { + // Look at and dampen the rotation + var rotation = Quaternion.LookRotation(target.position - transform.position); + transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); + } + else + { + // Just lookat + transform.LookAt(target); + } + } +} + +function Start () { + // Make the rigid body not change rotation + if (GetComponent.<Rigidbody>()) + GetComponent.<Rigidbody>().freezeRotation = true; +} \ No newline at end of file