static Transform Lerp( Transform a, Transform b, float t, bool clamp )

book_4_sparkGenerated
code_blocksInput

Description

The Transform.Lerp method is a static function that interpolates between two Transform instances, 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 a and 1 returns b. If clamp is set to true, the interpolation factor t will be clamped between 0 and 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 in a scene.

Parameters:

  • a: The starting Transform.
  • b: The ending Transform.
  • t: The interpolation factor, a float value.
  • clamp: A bool indicating whether to clamp t between 0 and 1.

Example

// Example of using 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 a transform halfway between startTransform and endTransform.