# LookRotation

> Creates a rotation with the specified forward and upwards directions.

## Definition

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

## LookRotation(Vector3, Vector3)

Creates a rotation with the specified `forward` and `upwards` directions.

```csharp
public static Quaternion LookRotation(Vector3 forward, Vector3 upwards)
```

### Parameters

**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The direction to look in, in world coordinates.**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The vector that defines in which direction up is, in world coordinates.

### Returns

| Type                                                                    | Description |
| ----------------------------------------------------------------------- | ----------- |
| [Quaternion](/engine/6000.5/script-reference/unityengine/quaternion.md) |             |

### Remarks

Z axis will be aligned with `forward`, X axis aligned with cross product between `forward` and `upwards`, and Y axis aligned with cross product between Z and X.

If the `forward` vector is zero, the method logs an error in the console and returns `identity`.

If `forward` and `upwards` are colinear, or if the magnitude of `upwards` is zero, the result is the same as [Quaternion.FromToRotation](/engine/6000.5/script-reference/unityengine/quaternion/fromtorotation.md) with `fromDirection` set to the positive Z-axis (0, 0, 1) and `toDirection` set to the normalized `forward` direction.

```csharp
// You can also use transform.LookAt

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Transform target;

    void Update()
    {
        Vector3 relativePos = target.position - transform.position;

        // the second argument, upwards, defaults to Vector3.up
        Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up);
        transform.rotation = rotation;
    }
}
```

Additional Resources: [Quaternion.SetLookRotation](/engine/6000.5/script-reference/unityengine/quaternion/setlookrotation.md).

## LookRotation(Vector3, Vector3)

Creates a rotation with the specified `forward` and `upwards` directions.

```csharp
public static Quaternion LookRotation(in Vector3 forward, in Vector3 upwards)
```

### Parameters

**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The direction to look in, in world coordinates.**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The vector that defines in which direction up is, in world coordinates.

### Returns

| Type                                                                    | Description |
| ----------------------------------------------------------------------- | ----------- |
| [Quaternion](/engine/6000.5/script-reference/unityengine/quaternion.md) |             |

### Remarks

Z axis will be aligned with `forward`, X axis aligned with cross product between `forward` and `upwards`, and Y axis aligned with cross product between Z and X.

If the `forward` vector is zero, the method logs an error in the console and returns `identity`.

If `forward` and `upwards` are colinear, or if the magnitude of `upwards` is zero, the result is the same as [Quaternion.FromToRotation](/engine/6000.5/script-reference/unityengine/quaternion/fromtorotation.md) with `fromDirection` set to the positive Z-axis (0, 0, 1) and `toDirection` set to the normalized `forward` direction.

```csharp
// You can also use transform.LookAt

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Transform target;

    void Update()
    {
        Vector3 relativePos = target.position - transform.position;

        // the second argument, upwards, defaults to Vector3.up
        Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up);
        transform.rotation = rotation;
    }
}
```

Additional Resources: [Quaternion.SetLookRotation](/engine/6000.5/script-reference/unityengine/quaternion/setlookrotation.md).
