Mathf.SmoothDamp Manual     Reference     Scripting  
Scripting > Runtime Classes > Mathf

static function SmoothDamp (current : float, target : float, ref currentVelocity : float, smoothTime : float, maxSpeed : float = Mathf.Infinity, deltaTime : float = Time.deltaTime) : float


Gradually changes a value towards a desired goal over time.

The value is smoothed by some spring-damper like function, which will never overshoot. The function can be used to smooth any kind of value, positions, colors, scalars. The most common use is for smoothing a follow camera.

current is the current position. target is the position we are trying to reach. currentVelocity is the current velocity, this value is modified by the function every time you call it. smoothTime is approximately the time it will take to reach the target. A smaller value will reach the target faster. maxSpeed optionally allows you to clamp the maximum speed. deltaTime is the time since the last call to this function. By default Time.deltaTime.

// Smooth towards the height of the target
var target : Transform;
var smoothTime = 0.3;
private var yVelocity = 0.0;

function Update ()
var newPosition = Mathf.SmoothDamp(transform.position.y, target.position.y,
yVelocity, smoothTime);
transform.position.y = newPosition;