# ProjectOnPlane

> Projects a vector onto a plane.

## Definition

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

## ProjectOnPlane(Vector3, Vector3)

Projects a vector onto a plane.

```csharp
public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal)
```

### Parameters

**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The vector to project on the plane.**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The normal which defines the plane to project on.

### Returns

| Type                                                              | Description                                                       |
| ----------------------------------------------------------------- | ----------------------------------------------------------------- |
| [Vector3](/engine/6000.5/script-reference/unityengine/vector3.md) | The vector that results from projection of `vector` on the plane. |

### Remarks

This method resolves the input vector onto the plane and returns the resulting vector. The new vector is orthogonal to `planeNormal` and parallel to the plane.

Note that `planeNormal` does not need to be normalized.

```csharp
// This example rotates a cube above a tilted plane. As the cube rotates, the cube's position vector is projected onto the plane and rendered as a line. 

using UnityEngine;

public class ProjectOnPlaneExampleUpdate: MonoBehaviour
{
 GameObject groundPlane;
 GameObject rotObject;
 LineRenderer line;


 void Start ()
 {
 // Create the plane
 groundPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);
 groundPlane.transform.Rotate(-30, 10, 0);

 // Create the item to rotate    
 rotObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
 rotObject.transform.position = new Vector3(5,5,0);
 line = rotObject.AddComponent<LineRenderer>();
 }

 void Update()
 {
 // Set the rotation origin
 Vector3 origin = Vector3.zero;

 // Rotate the object above the plane
 rotObject.transform.RotateAround(origin, Vector3.up, 20 * Time.deltaTime);

 // Project the location of the cube onto the plane
 Vector3 projected = Vector3.ProjectOnPlane(rotObject.transform.position, groundPlane.transform.up);

 // Draw the projected vector as a line
 line.SetPosition(0, origin);
 line.SetPosition(1, projected);
 line.startWidth = 0.1f;  

 }
}
```

Additional Resources: [Vector3.Project](/engine/6000.5/script-reference/unityengine/vector3/project.md), [Vector3.Reflect](/engine/6000.5/script-reference/unityengine/vector3/reflect.md).

## ProjectOnPlane(Vector3, Vector3)

Projects a vector onto a plane.

```csharp
public static Vector3 ProjectOnPlane(in Vector3 vector, in Vector3 planeNormal)
```

### Parameters

**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The vector to project on the plane.**** (\[Vector3]\(/engine/6000.5/script-reference/unityengine/vector3)): The normal which defines the plane to project on.

### Returns

| Type                                                              | Description                                                       |
| ----------------------------------------------------------------- | ----------------------------------------------------------------- |
| [Vector3](/engine/6000.5/script-reference/unityengine/vector3.md) | The vector that results from projection of `vector` on the plane. |

### Remarks

This method resolves the input vector onto the plane and returns the resulting vector. The new vector is orthogonal to `planeNormal` and parallel to the plane.

Note that `planeNormal` does not need to be normalized.

```csharp
// This example rotates a cube above a tilted plane. As the cube rotates, the cube's position vector is projected onto the plane and rendered as a line. 

using UnityEngine;

public class ProjectOnPlaneExampleUpdate: MonoBehaviour
{
 GameObject groundPlane;
 GameObject rotObject;
 LineRenderer line;


 void Start ()
 {
 // Create the plane
 groundPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);
 groundPlane.transform.Rotate(-30, 10, 0);

 // Create the item to rotate    
 rotObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
 rotObject.transform.position = new Vector3(5,5,0);
 line = rotObject.AddComponent<LineRenderer>();
 }

 void Update()
 {
 // Set the rotation origin
 Vector3 origin = Vector3.zero;

 // Rotate the object above the plane
 rotObject.transform.RotateAround(origin, Vector3.up, 20 * Time.deltaTime);

 // Project the location of the cube onto the plane
 Vector3 projected = Vector3.ProjectOnPlane(rotObject.transform.position, groundPlane.transform.up);

 // Draw the projected vector as a line
 line.SetPosition(0, origin);
 line.SetPosition(1, projected);
 line.startWidth = 0.1f;  

 }
}
```

Additional Resources: [Vector3.Project](/engine/6000.5/script-reference/unityengine/vector3/project.md), [Vector3.Reflect](/engine/6000.5/script-reference/unityengine/vector3/reflect.md).
