Created
March 30, 2011 00:09
-
-
Save tracend/893624 to your computer and use it in GitHub Desktop.
Unity3D: Camera script to smoothly look at any direction - Source: http://wiki.dreamsteep.com/Unity_tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (rigidbody) | |
rigidbody.freezeRotation = true; | |
} |
Thanks man o/
10 years ago but still helping : ) Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks a ton to make me remember this EQ.