Algorithm-interpolation calculation (1)-linear interpolation

Interpolation calculation is a commonly used algorithm in the development process, this article introduces linear interpolation

Code:

Vector3 end = new Vector3(250, 0, 300);
    //private void Update()
    //{
    //    transform.position = Vector3.Lerp(transform.position, end, 0.5f*Time.deltaTime);
    //}
Vector3.Lerp(transform.position, End, 0.1f*Time.deltaTime);

The principle of Learp linear interpolation:

First, transform.position is the start position, end is the end position, the third parameter is a percentage, the range is (0,1), Time.deltaTime time is unified, the running time of each machine may be different, and the runtime is Update Here, the position of Start is changing every frame.

Example: In the
following drawing example, start is the position of the object itself, end is the target position, and the percentage is 0.5
Algorithm-interpolation calculation (1)-linear interpolation

Linear interpolation is very simple, just take the position between the start and end positions.

Guess you like

Origin blog.51cto.com/myselfdream/2551546