Description
The Transform.Lerp
method is a static function that interpolates between two Transform
objects, a
and b
, based on a given interpolation factor t
. The method returns a new Transform
that represents the interpolated state between the two input transforms. The interpolation factor t
is a float
value typically between 0 and 1, where 0 returns the first transform a
, and 1 returns the second transform b
. If the clamp
parameter is set to true
, the method will clamp the interpolation factor t
to the range [0, 1].
Usage
Use this method when you need to smoothly transition between two transforms over time. This is particularly useful in animations or when moving objects smoothly from one position and orientation to another.
Ensure that the t
parameter is within the range [0, 1] if clamp
is set to false
, as values outside this range will extrapolate the transform beyond the given inputs.
Example
// Example usage of Transform.Lerp
Transform startTransform = new Transform
{
Position = new Vector3(0, 0, 0),
Rotation = Rotation.Identity,
Scale = new Vector3(1, 1, 1)
};
Transform endTransform = new Transform
{
Position = new Vector3(10, 10, 10),
Rotation = Rotation.FromAxis(Vector3.Up, 90),
Scale = new Vector3(2, 2, 2)
};
float interpolationFactor = 0.5f;
bool shouldClamp = true;
Transform resultTransform = Transform.Lerp(startTransform, endTransform, interpolationFactor, shouldClamp);
// resultTransform now represents the transform halfway between startTransform and endTransform.