Description
The Project
method of the Ray
struct calculates a point along the ray at a specified distance from the ray's origin. This method is useful for determining a position in 3D space that lies on the ray, given a certain distance from the starting point.
Usage
To use the Project
method, you need to have an instance of the Ray
struct. Call the method with a float
value representing the distance from the ray's origin. The method returns a Vector3
representing the point on the ray at the specified distance.
Example
// Create a Ray with a specific origin and direction
Ray ray = new Ray
{
Position = new Vector3(0, 0, 0),
Forward = new Vector3(1, 0, 0) // Direction along the x-axis
};
// Project a point 5 units along the ray
Vector3 pointOnRay = ray.Project(5.0f);
// Output the calculated point
// pointOnRay should be (5, 0, 0) since the ray is along the x-axis