Description
The Vector2.Lerp
method performs a linear interpolation between two Vector2
values, a
and b
, based on a given fraction frac
. This method is useful for smoothly transitioning between two points in 2D 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 Vector2.Lerp
method, provide two Vector2
instances representing the start and end points, a float
value for the interpolation fraction, and a bool
indicating whether to clamp the fraction.
Example usage:
Vector2 start = new Vector2(0, 0);
Vector2 end = new Vector2(10, 10);
float fraction = 0.5f;
bool shouldClamp = true;
Vector2 result = Vector2.Lerp(start, end, fraction, shouldClamp);
In this example, result
will be a Vector2
halfway between start
and end
, i.e., (5, 5)
.
Example
Vector2 start = new Vector2(0, 0);
Vector2 end = new Vector2(10, 10);
float fraction = 0.5f;
bool shouldClamp = true;
Vector2 result = Vector2.Lerp(start, end, fraction, shouldClamp);
// result is (5, 5)