Skip to content

Instantly share code, notes, and snippets.

@tracend
Created March 30, 2011 00:09
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracend/893624 to your computer and use it in GitHub Desktop.
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
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;
}
@clip911
Copy link

clip911 commented Feb 13, 2012

thanks a ton to make me remember this EQ.

@jlsystemabc
Copy link

Thanks man o/

@m1kx
Copy link

m1kx commented Apr 7, 2021

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