Mathf.SmoothStep

切换到手册

声明

public static float SmoothStep(float from, float to, float t);

参数

from 范围的开始。
to 范围的结束。
t fromto范围限制之间的插值值。

返回值

floatfromto之间插值的浮点数结果。

描述

fromto之间插值,并在限制处进行平滑处理。

此函数以类似于Lerp的方式在fromto之间插值。但是,插值将从开始逐渐加速,并在结束时逐渐减速。这对于创建自然逼真的动画、淡入淡出和其他过渡很有用。

参数t被限制在 [0, 1] 范围内。

using UnityEngine;

public class Example : MonoBehaviour { // Minimum and maximum values for the transition. float minimum = 10.0f; float maximum = 20.0f;

// Time taken for the transition. float duration = 5.0f;

float startTime;

void Start() { // Make a note of the time the script started. startTime = Time.time; }

void Update() { // Calculate the fraction of the total duration that has passed. float t = (Time.time - startTime) / duration; transform.position = new Vector3(Mathf.SmoothStep(minimum, maximum, t), 0, 0); } }

Did you find this page useful? Please give it a rating: