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.
The interpolation is calculated as:
result = a + (b - a) * frac
If the clamp
parameter is set to true
, the frac
value will be clamped between 0 and 1, ensuring the result does not exceed the bounds of a
and b
.
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
indicating whether to clamp the fraction.
This method is static and can be called directly on the Vector3
class.
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 not between 0 and 1.