Description
The LerpTo
method is an instance method of the Vector2
struct that performs a linear interpolation from the current vector to a target vector. The interpolation is controlled by a parameter t
, which represents the interpolation factor. Optionally, the result can be clamped to ensure it does not exceed the target vector.
Usage
To use the LerpTo
method, call it on an instance of Vector2
, passing in the target vector, the interpolation factor, and a boolean indicating whether to clamp the result.
The interpolation factor t
should be a value between 0 and 1, where 0 returns the current vector and 1 returns the target vector. If clamp
is set to true
, the result will be clamped between the current and target vectors.
Example
Vector2 current = new Vector2(0, 0);
Vector2 target = new Vector2(10, 10);
float t = 0.5f;
bool clamp = true;
Vector2 result = current.LerpTo(target, t, clamp);
// result will be (5, 5) if clamp is true, otherwise it will be the interpolated value without clamping.