Vector3 LerpTo( Vector3& target, float frac, bool clamp )
Vector3 LerpTo( Vector3& target, Vector3& frac, bool clamp )

book_4_sparkGenerated
code_blocksInput

Description

The Vector3.LerpTo method is used to interpolate between the current vector and a target vector. This method modifies the current vector to move it closer to the target vector by a specified fraction. Optionally, the interpolation can be clamped to ensure the result does not overshoot the target.

Usage

To use the LerpTo method, you need to provide the target vector, the fraction by which to interpolate, and a boolean indicating whether to clamp the result. The method will return a new Vector3 that represents the interpolated position.

Parameters:

  • target (ref Vector3): The target vector to interpolate towards.
  • frac (float): The fraction of the way to interpolate from the current vector to the target vector. A value of 0 will result in no change, while a value of 1 will result in the current vector being set to the target vector.
  • clamp (bool): If true, the interpolation will be clamped to ensure the result does not overshoot the target vector.

Example

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

Vector3 newPosition = currentPosition.LerpTo(ref targetPosition, fraction, shouldClamp);
// newPosition will be halfway between currentPosition and targetPosition, clamped if necessary.