Version: 2017.3

Mathf.SmoothDampAngle

切换到手册
public static float SmoothDampAngle (float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed= Mathf.Infinity, float deltaTime= Time.deltaTime);

参数

current 当前位置。
target 尝试达到的目标。
currentVelocity 当前速度,此值由函数在每次调用时进行修改。
smoothTime 达到目标所需的近似时间。值越小,达到目标的速度越快。
maxSpeed 可以选择允许限制最大速度。
deltaTime 自上次调用此函数以来的时间。默认情况下为 Time.deltaTime。

描述

随时间推移将以度为单位给定的角度逐渐改变为所需目标角度。

值通过某个类似于弹簧-阻尼的函数(它不会超过目标)进行平滑。该函数可以用于平滑任何类型的值、位置、颜色、标量。 最常见的用法是用于平滑跟随摄像机。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform target; public float smooth = 0.3F; public float distance = 5.0F; private float yVelocity = 0.0F; void Update() { float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, target.eulerAngles.y, ref yVelocity, smooth); Vector3 position = target.position; position += Quaternion.Euler(0, yAngle, 0) * new Vector3(0, 0, -distance); transform.position = position; transform.LookAt(target); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961