Description
The Vector3.Lerp
method performs a linear interpolation between two vectors, a
and b
, based on a given fraction frac
. This method is useful for smoothly transitioning between two points in 3D space.
If the clamp
parameter is set to true
, the interpolation fraction will be clamped between 0 and 1, ensuring that the result is always between a
and b
. If clamp
is false
, the fraction is not clamped, allowing for extrapolation beyond the two points.
Usage
To use the Vector3.Lerp
method, provide two Vector3
instances representing the start and end points, a float
value for the interpolation fraction, and a bool
to determine whether to clamp the fraction.
This method is static and can be called directly on the Vector3
struct.
Example
Vector3 start = new Vector3(0, 0, 0);
Vector3 end = new Vector3(10, 10, 10);
float fraction = 0.5f;
bool shouldClamp = true;
Vector3 result = Vector3.Lerp(start, end, fraction, shouldClamp);
// result is (5, 5, 5) if clamped, otherwise it could be outside the range if fraction is outside [0, 1]