# SmoothDamp

> Gradually changes a vector towards a desired goal over time.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## SmoothDamp(Vector2, Vector2, Vector2, float, float, float)

Gradually changes a vector towards a desired goal over time.

```csharp
public static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
```

### Parameters

**** (\[Vector2]\(/engine/6000.6/script-reference/unityengine/vector2)): The current position.**** (\[Vector2]\(/engine/6000.6/script-reference/unityengine/vector2)): The position we are trying to reach.**** (\[Vector2]\(/engine/6000.6/script-reference/unityengine/vector2)): The current velocity, this value is modified by the function every time you call it.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Approximately the time it will take to reach the target. A smaller value will reach the target faster.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Optionally allows you to clamp the maximum speed.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The time since the last call to this function. By default Time.deltaTime.

### Returns

| Type                                                              | Description                                                              |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [Vector2](/engine/6000.6/script-reference/unityengine/vector2.md) | The new position, moved part of the way from `current` towards `target`. |

### Remarks

The vector is smoothed by some spring-damper like function, which will never overshoot.

### Examples

```csharp
// Smooth towards the target

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Transform target;
    public float smoothTime = 0.3F;
    private Vector2 velocity = Vector2.zero;

    void Update()
    {
        // Define a target position above the target transform
        Vector2 targetPosition = target.TransformPoint(new Vector2(0, 5));

        // Smoothly move the camera towards that target position
        transform.position = Vector2.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
    }
}
```

## SmoothDamp(Vector2, Vector2, Vector2, float, float, float)

Gradually changes a vector towards a desired goal over time.

```csharp
public static Vector2 SmoothDamp(in Vector2 current, in Vector2 target, ref Vector2 currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
```

### Parameters

**** (\[Vector2]\(/engine/6000.6/script-reference/unityengine/vector2)): The current position.**** (\[Vector2]\(/engine/6000.6/script-reference/unityengine/vector2)): The position we are trying to reach.**** (\[Vector2]\(/engine/6000.6/script-reference/unityengine/vector2)): The current velocity, this value is modified by the function every time you call it.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Approximately the time it will take to reach the target. A smaller value will reach the target faster.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): Optionally allows you to clamp the maximum speed.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The time since the last call to this function. By default Time.deltaTime.

### Returns

| Type                                                              | Description                                                              |
| ----------------------------------------------------------------- | ------------------------------------------------------------------------ |
| [Vector2](/engine/6000.6/script-reference/unityengine/vector2.md) | The new position, moved part of the way from `current` towards `target`. |

### Remarks

The vector is smoothed by some spring-damper like function, which will never overshoot.

### Examples

```csharp
// Smooth towards the target

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Transform target;
    public float smoothTime = 0.3F;
    private Vector2 velocity = Vector2.zero;

    void Update()
    {
        // Define a target position above the target transform
        Vector2 targetPosition = target.TransformPoint(new Vector2(0, 5));

        // Smoothly move the camera towards that target position
        transform.position = Vector2.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
    }
}
```
