方法lerp是一个根据t来计算插值的,如果已知起始到目标都为固定,如果t每次都几乎一样,那么效果就是一下子快然后慢下来。
所以,就要控制t的大小是由小到大的,提供一个speed速度的概念,从0往上加到最高速度,因为刚开始的差值大,很小的t也会造成计算出来的插值很大,所以前面要控制t的成长变慢,后面再快。
using UnityEngine; public class ZhuanPanMono : MonoBehaviour { public static bool ShowResult = false; public static uint Result = 0; private float speed = 0f; public static float z = 0; private float heightSpeed = 3f; private float scaleSpeed = 0.18f; private Transform go; // Use this for initialization void Start () { go = transform.GetChild(3); } // Update is called once per frame void Update () { if (!ShowResult) return; uint TargetRotation = Result * 45 + 10 * 360; z = Mathf.Lerp(z, TargetRotation, Time.deltaTime * speed); go.rotation = Quaternion.Euler(go.rotation.x,go.rotation.y,z); if (speed < heightSpeed) { //通过缩放来控制前期速度的增长过快 speed += Time.deltaTime * scaleSpeed; } if (scaleSpeed < 1 && speed > 1f) { //后期释放加速度的限制缩放 scaleSpeed += Time.deltaTime; } if (Mathf.Abs(z - TargetRotation) < 0.1f) { //转动结束 ShowResult = false; } } }