Unity - Scripting API: Vector3.Project
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Description
Projects a vector onto another vector.
To understand vector projection, imagine that onNormal is resting on a line pointing in its
direction. Somewhere along that line will be the nearest point to the tip of vector. The
projection is just onNormal rescaled so that it reaches that point on the line.

A full line with an arrow representing vector extends upwards and to the left. A full line with an arrow representing the vector onNormal extends from the same origin point straight upwards by a smaller y component. A dotted line, representing the projection, further extends onNormal to the point closest to the tip of vector.
The function returns a zero vector if onNormal is almost zero.
An example of the usage of projection is a rail-mounted gun that should slide so that it gets as close as possible to a target object. The projection of the target heading along the direction of the rail can be used to move the gun by applying a force to a rigidbody, say.