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

robot_2Generated
code_blocksInput

Description

The LerpTo method is used to linearly interpolate between the current Vector3 instance and a target Vector3. 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, call it on an instance of Vector3, passing in the target vector, the interpolation fraction, and a boolean indicating whether to clamp the result.

Parameters:

  • target (ref Vector3): The target vector to interpolate towards.
  • frac (float): The fraction of the distance to move towards the target. A value of 0 will result in no movement, while a value of 1 will move directly to the target.
  • clamp (bool): If true, the interpolation will be clamped to prevent overshooting the target.

Returns: A new Vector3 that is the result of the interpolation.

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.