返回介绍

Vector3.SmoothDamp 平滑阻尼

发布于 2019-12-18 15:38:44 字数 2808 浏览 1772 评论 0 收藏 0

JavaScript => static function SmoothDamp(current: Vector3, target: Vector3, currentVelocity: Vector3, smoothTime: float, maxSpeed: float = Mathf.Infinity, deltaTime: float = Time.deltaTime): Vector3;
C# => static Vector3 SmoothDamp(Vector3 current, Vector3 target, Vector3 currentVelocity, float smoothTime, float maxSpeed = Mathf.Infinity, float deltaTime = Time.deltaTime);

Parameters 参数

currentThe current position.
当前位置坐标。
targetThe position we are trying to reach.
想要达到的位置。
currentVelocityThe current velocity, this value is modified by the function every time you call it.
当前速度,该值由每次调用该函数时修改。
smoothTimeApproximately the time it will take to reach the target. A smaller value will reach the target faster.
达到目标大约花费的时间。 一个较小的值将更快达到目标。
maxSpeedOptionally allows you to clamp the maximum speed.
选择允许你限制的最大速度。
deltaTimeThe time since the last call to this function. By default Time.deltaTime.
自上次调用这个函数。默认情况下是 Time.deltaTime。

Description 描述

Gradually changes a vector towards a desired goal over time.

随着时间的推移,逐渐改变一个向量朝向预期的目标。

The vector is smoothed by some spring-damper like function, which will never overshoot. The most common use is for smoothing a follow camera.

向量由一些像弹簧阻尼器函数平滑,这将永远不会超过。最常见的用途是平滑跟随相机。

JavaScript:

	// Smooth towards the target	var target : Transform;
	var smoothTime = 0.3;
	private var velocity = Vector3.zero;
 
	function Update () {
		// Define a target position above and behind the target transform
		var targetPosition : Vector3 = target.TransformPoint(Vector3(0, 5, -10));
 
		// Smoothly move the camera towards that target position
		transform.position = Vector3.SmoothDamp(transform.position, targetPosition,
		                             velocity, smoothTime);
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Transform target;
    public float smoothTime = 0.3F;
    private Vector3 velocity = Vector3.zero;
    void Update() {
        Vector3 targetPosition = target.TransformPoint(new Vector3(0, 5, -10));
        transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
    }
}

Vector3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文