Vector3.ProjectOnPlane
时间: 2024-04-29 09:24:16 浏览: 68
(Vector3 vector, Vector3 planeNormal)
Returns a vector that is the projection of the input vector onto a plane defined by the input normal vector.
- `vector`: The input vector to be projected.
- `planeNormal`: The normal vector of the plane onto which the input vector will be projected.
```csharp
public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal);
```
Example usage:
```csharp
Vector3 inputVector = new Vector3(1, 2, 3);
Vector3 planeNormal = new Vector3(0, 1, 0);
Vector3 projectedVector = Vector3.ProjectOnPlane(inputVector, planeNormal);
Debug.Log(projectedVector); // Output: (1, 0, 3)
```
In this example, we have an input vector (1, 2, 3) and a plane with a normal vector pointing in the y direction (0, 1, 0). Calling `Vector3.ProjectOnPlane()` with these inputs returns a vector (1, 0, 3) which is the projection of the input vector onto the plane. The x and z components of the input vector are preserved while the y component is set to zero since the projection is perpendicular to the plane's normal vector.
阅读全文