Description
The Vector3.SlerpTo
method performs a spherical linear interpolation (slerp) between the current vector and a target vector. This method is useful for smoothly interpolating between two vectors, such as for animations or gradual transitions in 3D space.
Usage
To use the SlerpTo
method, call it on an instance of Vector3
, passing in the target vector, the interpolation fraction, and a boolean indicating whether to clamp the result.
target
: The target vector to interpolate towards.
frac
: A float
representing the interpolation fraction. A value of 0 returns the current vector, while a value of 1 returns the target vector.
clamp
: A bool
indicating whether to clamp the interpolation fraction between 0 and 1.
Example
Vector3 current = new Vector3(1, 0, 0);
Vector3 target = new Vector3(0, 1, 0);
float fraction = 0.5f;
bool clamp = true;
Vector3 result = current.SlerpTo(ref target, fraction, clamp);
// result will be a vector halfway between current and target on the unit sphere.