版本: Unity 6 (6000.0)
语言English
  • C#

Vector3.Slerp

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们会阅读用户提出的每一个建议更改,并在适用情况下进行更新。

关闭

提交失败

由于某些原因,您的建议更改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

声明

public static Vector3 Slerp(Vector3 a, Vector3 b, float t);

描述

在两个向量之间进行球面插值。

通过 t 的量在 ab 之间进行插值。这与线性插值(又名“lerp”)的区别在于,向量被视为方向而不是空间中的点。返回向量的方向由角度插值,其大小fromto 的大小之间进行插值。

参数 t 被钳制到 [0, 1] 范围内。

// Animates the position in an arc between sunrise and sunset.

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform sunrise; public Transform sunset;

// Time to move from sunrise to sunset position, in seconds. public float journeyTime = 1.0f;

// The time at which the animation started. private float startTime;

void Start() { // Note the time at the start of the animation. startTime = Time.time; }

void Update() { // The center of the arc Vector3 center = (sunrise.position + sunset.position) * 0.5F;

// move the center a bit downwards to make the arc vertical center -= new Vector3(0, 1, 0);

// Interpolate over the arc relative to center Vector3 riseRelCenter = sunrise.position - center; Vector3 setRelCenter = sunset.position - center;

// The fraction of the animation that has happened so far is // equal to the elapsed time divided by the desired time for // the total journey. float fracComplete = (Time.time - startTime) / journeyTime;

transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, fracComplete); transform.position += center; } }

其他资源:LerpSlerpUnclamped