Blogger Information
Blog 95
fans 0
comment 11
visits 248820
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
关于游戏开发中的插值运算Lerp
龍__遇见彩虹的博客
Original
1612 people have browsed it

Mathf.Lerp

public static float Lerp(float a, float b, float t);


Description

Linearly interpolates between a and b by t.

The parameter t is clamped to the range [0, 1].

When t = 0 returns a.
When t = 1 return b.
When t = 0.5 returns the midpoint of a and b.

using UnityEngine;
using System.Collections;
/*
 *Lerp插值运算
 *速度会慢慢的减少
 */
public class DemoController : MonoBehaviour {
    //public Transform cube;
    public GameObject cube;
    private void Update()
    {
        //float x = cube.position.x;
        float x = cube.transform.position.x;
        
        float newX = Mathf.Lerp(x, 10, Time.deltaTime);
        //float newX = Mathf.Lerp(x, 10, 0.1f);
        
        //cube.position = new Vector3(newX, 0, 0);
        cube.transform.position = new Vector3(newX, 0, 0);
    }
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post