UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Vector3.Slerp
# [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html).Slerp public static [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **Slerp** ([Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **a**, [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **b**, float **t**); ## 描述 在两个向量之间进行球形插值。 在 `a` 和 `b` 之间按大小 `t` 进行插值。 球形插值与线性插值(也称为“lerp”)的区别在于, 向量被视为方向而不是空间中的点。返回的向量的方向通过角度进行插值, 其 [magnitude](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3-magnitude.html) 在 `from` 和 `to` 的大小之间进行插值。 参数 `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; } } ``` 另请参阅:[Lerp](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.Lerp.html)、[SlerpUnclamped](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.SlerpUnclamped.html)。
da
2022年6月22日 10:59
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码