# Unity Slerp: How to Smoothly Rotate Objects in Unity

How To Use Unity Slerp in your game Imagine you're creating a 3D game where an enemy needs to turn towards the player before attacking. Or perhaps your camera needs to follow a moving character without making sudden, jerky movements. How can you make these rotations feel smooth and natural? **Unity Slerp** provides a simple way to achieve this using quaternion interpolation. With `Quaternion.Slerp()`, you can smoothly transition an object's rotation from one orientation to another without manually calculating every angle.

Whether you're developing a 2D or 3D game, working on enemy AI, building a third-person camera, or animating interactive objects, smooth rotation can make your gameplay feel more polished. Instead of instantly changing an object's direction, you can gradually move it towards its target rotation.

In this tutorial, you'll learn how Unity Slerp works, how to use `Quaternion.Slerp()` in C#, and how to control rotation behaviour in real gameplay situations. We'll also compare Slerp with Lerp and RotateTowards, explore common mistakes, and build practical examples you can use in your own Unity projects.

## What Is Unity Slerp?

**Slerp** stands for *Spherical Linear Interpolation*. In Unity, `Quaternion.Slerp()` is used to interpolate between two rotations along a spherical path.

In simple terms, imagine a character standing in a scene. The character is facing forward, but an enemy appears on its left. Instead of instantly turning towards the enemy, you want the character to rotate gradually. Slerp helps you create that smooth transition.

Unity represents 3D rotations using Quaternions. Rather than directly changing the X, Y, and Z rotation angles, you provide a starting Quaternion, a target Quaternion, and an interpolation value.

The basic syntax is:

```plaintext
Quaternion.Slerp(startRotation, targetRotation, t);
```

Here:

- `startRotation` is the rotation where the interpolation begins.
- `targetRotation` is the desired final rotation.
- `t` is the interpolation value, normally between `0` and `1`.

When `t` is `0`, the result is the starting rotation. When `t` is `1`, the result is the target rotation. Values between them produce intermediate rotations.

**Important:** `t` is not an angle or a rotation speed. It represents progress between the two rotations. How you calculate and update it determines how the rotation behaves over time.

## Why Use Slerp for Object Rotation in Unity?

You can change an object's rotation directly by assigning a new value to `transform.rotation`. However, an immediate change can look unnatural when the object is supposed to turn gradually.

For example, consider an enemy that detects the player. If its rotation changes instantly, it may look as if the enemy is snapping towards the player. A gradual rotation makes the movement feel more believable.

Unity Slerp is useful when you want to:

- Rotate enemies smoothly towards the player.
- Create camera transitions without sudden changes.
- Turn vehicles towards a new direction.
- Animate doors, turrets, weapons, and other 3D objects.
- Blend between two predefined orientations.

It is particularly useful when you want to interpolate between two 3D orientations rather than manually calculate the rotation angles.

## How Does Quaternion.Slerp() Work in Unity?

To understand Slerp, you need to know about its three main inputs: the starting rotation, the target rotation, and the interpolation value.

### 1\. Starting Rotation

This is the object's current or initial orientation. You can get the current rotation using:

```plaintext
Quaternion startRotation = transform.rotation;
```

### 2\. Target Rotation

This is the orientation you want the object to reach. You can create a target rotation using `Quaternion.Euler()` or calculate one using `Quaternion.LookRotation()`.

For example:

```plaintext
Quaternion targetRotation = Quaternion.Euler(0f, 90f, 0f);
```

This creates a rotation of 90 degrees around the Y-axis.

### 3\. Interpolation Value (t)

The third parameter controls how far the result moves between the starting and target rotations.

| t value | Result |
| --- | --- |
| 0 | Starting rotation |
| 0.25 | 25% interpolation |
| 0.5 | Halfway interpolation |
| 0.75 | 75% interpolation |
| 1 | Target rotation |

For a rotation that progresses over a fixed duration, you can calculate `t` using elapsed time divided by the desired duration. We'll use this approach in a practical example below.

## How to Smoothly Rotate an Object Towards a Target

Let's create a simple example where a GameObject rotates to face another GameObject in the scene.

This technique is useful for enemy AI, turrets, characters, and other objects that need to look towards a target.

### Step 1: Prepare the Unity Scene

1. Create a 3D Unity project or open an existing one.
2. Add a Cube to the scene. This will be the object that rotates.
3. Add a Sphere to the scene. This will act as the target.
4. Position the Sphere somewhere in front of or beside the Cube.
5. Create a C# script named `SmoothRotation`.
6. Attach the script to the Cube.

### Step 2: Write the C# Script

Open the `SmoothRotation` script and add the following code:

```plaintext
using UnityEngine;
```

`public class SmoothRotation : MonoBehaviour\ {\ public Transform target;\ public float rotationSpeed = 2f;`

```plaintext
void Update()
{
    if (target == null)
        return;

    // Calculate the direction towards the target
    Vector3 direction = target.position - transform.position;

    // Avoid calculating a rotation from a zero direction
    if (direction.sqrMagnitude &lt; 0.0001f)
        return;

    // Calculate the target rotation
    Quaternion targetRotation = Quaternion.LookRotation(direction);

    // Smoothly rotate towards the target
    transform.rotation = Quaternion.Slerp(
        transform.rotation,
        targetRotation,
        rotationSpeed * Time.deltaTime
    );
}
```

`}`

### Step 3: Assign the Target

\
Select the Cube in the Hierarchy. In the Inspector, find the `SmoothRotation` component and drag the Sphere into its **Target** field.\\

Now press Play. The Cube should gradually rotate towards the Sphere.

### Understanding the Code

\
Let's look at the important parts.\\

**Getting the direction**

```plaintext
Vector3 direction = target.position - transform.position;
```

This calculates the direction from the rotating object towards the target.

**Calculating the target rotation**

```plaintext
Quaternion targetRotation = Quaternion.LookRotation(direction);
```

`Quaternion.LookRotation()` creates a rotation that points the object's forward direction along the supplied direction vector.

**Applying Slerp**

```plaintext
transform.rotation = Quaternion.Slerp(
    transform.rotation,
    targetRotation,
    rotationSpeed * Time.deltaTime
);
```

This gradually adjusts the object's rotation towards the target rotation.

Here, `Time.deltaTime` makes the interpolation factor depend on frame time, helping the smoothing behave consistently across different frame rates. Because the current rotation is used as the starting point every frame, this produces an easing-style approach: the object gets closer to the target and gradually slows down rather than rotating at a constant angular speed.

**Tip:** This example assumes the object's local forward axis is its intended facing direction. If your model faces another axis, you may need to adjust the model or apply a rotation offset.

## How to Control Rotation Speed Using Unity Slerp

\
One of the most common questions developers have is: how can you control how quickly an object rotates using Slerp?\\

The answer depends on how you calculate the interpolation value. Remember, the third parameter of `Quaternion.Slerp()` is not directly a speed in degrees per second. It controls the interpolation progress between two rotations.

### Method 1: Smoothly Approach a Target Rotation

\
If you want an object to keep moving closer to a target rotation, you can use the current rotation as the starting point every frame:\\

```plaintext
using UnityEngine;
```

`public class SmoothRotation : MonoBehaviour\ {\ public Transform target;\ public float smoothSpeed = 3f;`

```plaintext
void Update()
{
    if (target == null)
        return;

    transform.rotation = Quaternion.Slerp(
        transform.rotation,
        target.rotation,
        smoothSpeed * Time.deltaTime
    );
}
```

`}`

\
Increase `smoothSpeed` to make the object approach the target more quickly. Decrease it for a slower, softer rotation.

Keep in mind that this approach gets progressively closer to the target. It does not guarantee that the object will finish rotating within a fixed duration or maintain a constant angular speed.

### Method 2: Rotate Between Two Orientations Over a Fixed Duration

\
Sometimes you want an object to complete its rotation within a specific amount of time. For example, a door might need to rotate from its closed position to its open position in one second.\\

In this situation, store the starting rotation and calculate the interpolation value using elapsed time.

```plaintext
using UnityEngine;

public class TimedRotation : MonoBehaviour
{
    public Vector3 targetEulerAngles = new Vector3(0f, 90f, 0f);
    public float duration = 1f;

    private Quaternion startRotation;
    private Quaternion targetRotation;
    private float elapsedTime;

    void Start()
    {
        startRotation = transform.rotation;
        targetRotation = Quaternion.Euler(targetEulerAngles);
    }

    void Update()
    {
        if (elapsedTime >= duration)
            return;

        elapsedTime += Time.deltaTime;

        float t = Mathf.Clamp01(elapsedTime / duration);

        transform.rotation = Quaternion.Slerp(
            startRotation,
            targetRotation,
            t
        );
    }
}
```

Here is what happens:

- `startRotation` stores the object's original orientation.
- `targetRotation` stores the desired final orientation.
- `elapsedTime` tracks how long the rotation has been running.
- `t` gradually increases from 0 to 1.
- When the duration ends, the object reaches its target rotation.

\
For example, if the duration is set to two seconds, the rotation completes in approximately two seconds, assuming the object is not interrupted by another script.\\

**Tip:** This method is useful for doors, rotating platforms, UI elements, and scripted camera transitions. If you want a rotation that moves at a consistent angular speed instead, consider `Quaternion.RotateTowards()`.

## Unity Slerp vs Lerp: What Is the Difference?

\
Unity provides two commonly used Quaternion interpolation methods: `Quaternion.Slerp()` and `Quaternion.Lerp()`. Both help you transition between two rotations, but they use different interpolation approaches.\\

`Quaternion.Slerp()` performs spherical interpolation between two unit Quaternions. `Quaternion.Lerp()` performs linear interpolation and normalizes the resulting Quaternion. Lerp is generally faster, while Slerp provides more consistent angular interpolation when the rotations are far apart.

| Feature | Quaternion.Slerp() | Quaternion.Lerp() |
| --- | --- | --- |
| Interpolation | Spherical | Linear, followed by normalization |
| Rotation path | Spherical interpolation | Normalized linear interpolation |
| Performance | Generally more computationally expensive | Generally faster |
| Angular velocity | More consistent for rotations between fixed endpoints | May vary, especially for larger angular differences |
| Best suited for | Smooth rotation transitions | Lightweight rotation interpolation |

### Example: Using Quaternion.Lerp()

\
You can use Lerp in a similar way to Slerp:\\

```plaintext
using UnityEngine;
```

`public class SmoothLerpRotation : MonoBehaviour\ {\ public Transform target;\ public float smoothSpeed = 3f;`

```plaintext
void Update()
{
    if (target == null)
        return;

    transform.rotation = Quaternion.Lerp(
        transform.rotation,
        target.rotation,
        smoothSpeed * Time.deltaTime
    );
}
```

`}`

\
Both examples create a smoothing effect because they use the object's current rotation as the starting point every frame.

So, which one should you choose? Use Slerp when the spherical interpolation behaviour is important to your rotation. Use Lerp when you want a simpler, generally faster interpolation and its rotation behaviour is suitable for your game.

If you want to understand interpolation in more detail, check out our tutorial: [How to Master the Unity Lerp Function in 5 Easy Steps](https://learngamestutorial.com/how-to-master-in-unity-lerp-function/).

## Unity Slerp vs RotateTowards: Which Should You Use?

\
Another useful method for rotating objects is `Quaternion.RotateTowards()`. Unlike Slerp, which uses an interpolation ratio, RotateTowards moves a rotation towards its target by a maximum angular step.\\

This makes RotateTowards particularly useful when you want to control rotation speed in degrees per second.

### Example: Rotate an Object at a Fixed Angular Speed

```plaintext
using UnityEngine;
```

`public class RotateTowardsTarget : MonoBehaviour\ {\ public Transform target;\ public float rotationSpeed = 120f;`

```plaintext
void Update()
{
    if (target == null)
        return;

    float step = rotationSpeed * Time.deltaTime;

    transform.rotation = Quaternion.RotateTowards(
        transform.rotation,
        target.rotation,
        step
    );
}
```

`}`

\
In this example, `rotationSpeed` represents the maximum rotation speed in degrees per second. Multiplying it by `Time.deltaTime` calculates the maximum rotation step for the current frame.

RotateTowards also avoids overshooting the target rotation.

| Method | How it works | Best use case |
| --- | --- | --- |
| `Quaternion.Slerp()` | Interpolates between two rotations using a ratio. | Smooth rotation transitions. |
| `Quaternion.Lerp()` | Uses normalized linear interpolation. | Lightweight rotation smoothing. |
| `Quaternion.RotateTowards()` | Moves towards a target by a maximum angular step. | Controlled angular speed. |

\
There is no single method that is best for every situation. Choose the one that matches the rotation behaviour you want to achieve.\\

## Practical Unity Slerp Examples in Game Development

\
Now that you understand how Slerp works, let's look at some situations where it can improve your game's movement and visual quality.\\

### 1\. Smoothly Rotate an Enemy Towards the Player

\
In an action or shooting game, enemies often need to face the player before attacking. Instead of changing their rotation instantly, you can smoothly rotate them towards the player's position.\\

```plaintext
using UnityEngine;
```

`public class EnemyRotation : MonoBehaviour\ {\ public Transform player;\ public float rotationSpeed = 4f;`

```plaintext
void Update()
{
    if (player == null)
        return;

    Vector3 direction = player.position - transform.position;

    // Ignore vertical difference for a ground-based enemy
    direction.y = 0f;

    if (direction.sqrMagnitude &lt; 0.0001f)
        return;

    Quaternion targetRotation =
        Quaternion.LookRotation(direction);

    transform.rotation = Quaternion.Slerp(
        transform.rotation,
        targetRotation,
        rotationSpeed * Time.deltaTime
    );
}
```

`}`

\
This example is suitable for a ground-based enemy that should rotate around its Y-axis. You can adjust the rotation speed to make the enemy turn slowly or react more quickly.

### 2\. Smoothly Rotate a Camera Towards a Target

\
Camera movement plays an important role in the overall feel of a game. Sudden camera rotation can make gameplay feel uncomfortable, especially in third-person games.\\

You can use Slerp in `LateUpdate()` to smoothly adjust the camera's orientation after the player and other objects have updated during the frame.

```plaintext
using UnityEngine;

public class SmoothCameraRotation : MonoBehaviour
{
    public Transform target;
    public float rotationSpeed = 5f;

    void LateUpdate()
    {
        if (target == null)
            return;

        Vector3 direction = target.position - transform.position;

        if (direction.sqrMagnitude < 0.0001f)
            return;

        Quaternion targetRotation =
            Quaternion.LookRotation(direction);

        transform.rotation = Quaternion.Slerp(
            transform.rotation,
            targetRotation,
            rotationSpeed * Time.deltaTime
        );
    }
}
```

This example smoothly rotates the camera to look at the target. It does not move the camera's position or create a complete third-person camera system; those behaviours need to be implemented separately.

### 3\. Rotate a Turret Towards an Enemy

\
In a tower defense or shooting game, a turret needs to turn towards an approaching enemy before firing. Slerp can help create a smooth aiming movement.\\

```plaintext
using UnityEngine;
```

`public class TurretRotation : MonoBehaviour\ {\ public Transform enemy;\ public float rotationSpeed = 6f;`

```plaintext
void Update()
{
    if (enemy == null)
        return;

    Vector3 direction = enemy.position - transform.position;

    if (direction.sqrMagnitude &lt; 0.0001f)
        return;

    Quaternion targetRotation =
        Quaternion.LookRotation(direction);

    transform.rotation = Quaternion.Slerp(
        transform.rotation,
        targetRotation,
        rotationSpeed * Time.deltaTime
    );
}
```

`}`

\
For a real turret, you may want to rotate only the horizontal base or a separate aiming part. You can also add a check to fire only when the turret is sufficiently close to its target direction.

### 4\. Smoothly Rotate a Door or Interactive Object

\
Slerp is also useful for objects that rotate between two predefined orientations. For example, you can use it to open a door, rotate a machine part, or animate an interactive object.\\

For this type of animation, the fixed-duration example shown earlier is a good starting point. Store the closed rotation, calculate the open rotation, and increase the interpolation value over the desired animation duration.

## Common Unity Slerp Mistakes and How to Fix Them

\
Although Quaternion.Slerp is straightforward to use, a few common mistakes can cause unexpected rotation behaviour.\\

### 1\. Treating t as Rotation Speed

\
The `t` parameter represents interpolation progress, not degrees per second. If you need a specific angular speed, use `Quaternion.RotateTowards()` or calculate the interpolation progress over a fixed duration.\\

### 2\. Forgetting Time.deltaTime

\
When updating interpolation over multiple frames, forgetting to account for elapsed time can make the behaviour depend on the frame rate. Use `Time.deltaTime` when calculating a time-based interpolation value or angular step.\\

### 3\. Recalculating the Starting Rotation Every Frame for a Timed Animation

\
If you want a rotation to finish within a fixed duration, do not repeatedly replace the original starting rotation with the current rotation. Store the initial rotation once, then interpolate from that stored value to the target.\\

### 4\. Using an Incorrect Target Direction

\
If you use `Quaternion.LookRotation()`, make sure the direction vector is valid and not zero. Also check that your model's forward axis matches the direction you want it to face.\\

### 5\. Using Slerp When You Need Constant Angular Speed

\
Slerp is designed for interpolation between rotations, not for directly specifying degrees per second. If an enemy, vehicle, or turret must rotate at a controlled angular speed, `Quaternion.RotateTowards()` is often a better option.\\

### 6\. Updating the Same Rotation from Multiple Scripts

\
If multiple scripts modify the same object's rotation, they may overwrite each other's changes. Keep rotation control in one place where possible, or coordinate the scripts so that they do not compete.\\

## Unity Slerp Best Practices

\
Follow these practices to get predictable rotation behaviour in your Unity projects:\\

- Use `Quaternion.Slerp()` when spherical interpolation between rotations is useful.
- Store the initial rotation when creating a fixed-duration rotation animation.
- Use `Time.deltaTime` for frame-rate-independent time calculations.
- Use `Quaternion.RotateTowards()` when you need a maximum angular speed.
- Check target references before accessing their Transform properties.
- Make sure direction vectors passed to `Quaternion.LookRotation()` are valid.
- Avoid having multiple scripts control the same Transform rotation without coordination.
- Test rotation behaviour with different frame rates and target positions.

\
If you are learning how Unity executes scripts every frame, you may also find our guide on [Unity Update vs FixedUpdate](https://prep.alokkrishali.com/questions/unity-update-fixedupdate) helpful.\\

## Conclusion

**Unity Slerp** is a useful technique for creating smooth transitions between object rotations. Whether you are rotating an enemy towards the player, adjusting a camera, aiming a turret, or animating an interactive object, `Quaternion.Slerp()` can help make your gameplay feel more natural.\\

The most important thing is to understand how its interpolation value works. Use a progressively updated value when you want a smooth approach towards a target, and use a stored starting rotation with elapsed time when you need a transition to finish within a specific duration. If your goal is constant angular speed, consider `Quaternion.RotateTowards()` instead.

Try these examples in a small Unity scene and experiment with different rotation speeds and target positions. Once you understand how these methods behave, you can use them to create better camera controls, enemy movement, vehicle behaviour, and other gameplay systems.

## Frequently Asked Questions (FAQs)

### 1\. What is Unity Slerp used for?

\
Unity Slerp is used to smoothly interpolate between two rotations. It is commonly used for rotating characters, cameras, enemies, turrets, vehicles, and other GameObjects towards a target orientation.\\

### 2\. What is the difference between Quaternion.Slerp and Quaternion.Lerp?

`Quaternion.Slerp()` uses spherical interpolation, while `Quaternion.Lerp()` uses normalized linear interpolation. Lerp is generally faster, but Slerp provides more consistent angular interpolation when the rotations are far apart.\\

### 3\. Is Unity Slerp frame-rate independent?

\
Slerp itself does not automatically make an animation frame-rate independent. You need to calculate its interpolation value using elapsed time or another appropriate time-based calculation. For example, use `Time.deltaTime` when updating elapsed time or a smoothing factor.\\

### 4\. How do I make an object rotate faster using Slerp?

\
If you are using the current rotation as the starting point every frame, increasing the smoothing factor will make the object approach the target more quickly. If you are using a fixed-duration rotation, reduce the duration to complete the transition sooner.\\

### 5\. Can I use Quaternion.Slerp in FixedUpdate?

\
Yes. You can use Quaternion.Slerp in `FixedUpdate()` when rotation is part of a physics-related update. For ordinary visual rotation, `Update()` is commonly used. For camera rotation that follows an object, `LateUpdate()` is often useful. Choose the update method according to how the object is controlled.\\

### 6\. Should I use Slerp or RotateTowards for enemy rotation?

\
It depends on the behaviour you want. Use Slerp when you want a smooth interpolation towards a target orientation. Use RotateTowards when you want to limit how many degrees the enemy can rotate per second. Both are useful for enemy AI.\\

## Thanks for Reading!

\
Thank you for taking the time to read this Unity Slerp tutorial. I hope these explanations and practical C# examples help you create smoother rotation behaviour in your Unity games.\\

If you found this tutorial helpful, please share it with other Unity developers, leave a comment about how you use Quaternion.Slerp in your projects, and explore more game development tutorials at [LearnGameTutorial](https://learngamestutorial.com/).

Keep learning, keep experimenting, and happy game development!

---

**Further Reading:**

- [Unity Documentation: Quaternion.Slerp](https://docs.unity.com/en-us/engine/6000.0/script-reference/unityengine/quaternion/slerp)
- [Unity Documentation: Quaternion.Lerp](https://docs.unity.com/en-us/engine/6000.0/script-reference/unityengine/quaternion/lerp)
- [Unity Documentation: Quaternion.RotateTowards](https://docs.unity.cn/6000.0/Documentation/ScriptReference/Quaternion.RotateTowards.html)
- [LearnGameTutorial: How to Master the Unity Lerp Function](https://learngamestutorial.com/how-to-master-in-unity-lerp-function/)
- [Prep: Unity Update vs FixedUpdate](https://prep.alokkrishali.com/questions/unity-update-fixedupdate)
