static Vector3 Lerp( Vector3 a, Vector3 b, float frac, bool clamp )
static Vector3 Lerp( Vector3& a, Vector3& b, Vector3 frac, bool clamp )

book_4_sparkGenerated
code_blocksInput

Description

The Vector3.Lerp method performs a linear interpolation between two vectors, a and b, based on a given fraction frac. This method is useful for smoothly transitioning between two points in 3D space.

The interpolation is calculated as:

result = a + (b - a) * frac

If the clamp parameter is set to true, the frac value will be clamped between 0 and 1, ensuring the result is always between a and b.

Usage

Use this method when you need to interpolate between two 3D points. This is particularly useful in animations, simulations, or any scenario where a smooth transition is required.

Ensure that the frac parameter is within the range of 0 to 1 for meaningful results, unless clamping is enabled.

Example

Vector3 pointA = new Vector3(0, 0, 0);
Vector3 pointB = new Vector3(10, 10, 10);
float fraction = 0.5f;
bool shouldClamp = true;

Vector3 interpolatedPoint = Vector3.Lerp(pointA, pointB, fraction, shouldClamp);
// interpolatedPoint will be (5, 5, 5) if clamping is enabled and fraction is 0.5