Unity 的 Mathf.PingPong 实际上是做什么的?

2023-11-24

Unity 文档用于数学乒乓球 says:

乒乓球的价值t,因此它永远不会大于length并且永远不会小于0.

我知道它正在 0 到 0 之间旋转一个值length,我不明白的是价值是什么t它与 PingPong 的运作方式有何关系?

如果我设置t对于任何常数,我总是能得到那个值

void Update()
{
// always prints: 1
    print(Mathf.PingPong(1f, 1f));

// always prints 0
    print(Mathf.PingPong(0f, 1f));
}

每次我看到 PingPong 在示例中使用时,它都会Time.time用于t值(或一些基于的数学Time.time). Why?

我看到的唯一解释来自这个问题:时间:2019-03-17 标签:c#UnityMathf.PingPong不工作这意味着t一定总是在变化,但同样不清楚为什么或发生了什么。

那么,什么是Mathf.PingPong实际上在做t/ 值是多少t实际上是为了,如何正确使用该功能?


So Mathf.PingPong()使用函数调用Mathf.Repeat()

这些可能旨在作为补间/缓动辅助函数

So Mathf.Repeat(float t, float length) will create a graph like this
enter image description here
Where length is the length of each line segment, and t is the X value of the function (the return value being the corresponding Y position on the graph)

What Mathf.PingPong(float t, float length) does looks more like this
enter image description here
Again where length describes the height of each triangle and t gives the X position

一个常见的用例是我们想要改变一些值随着这张图,就像沿着它行走,X 值稳步增加,并在每一步取 Y 值。 最简单的方法是通过Time.time在作为t参数,它将获取该函数在相应 X 位置的值。

float Y = Mathf.PingPong(Time.time,Max_Y_Value);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Unity 的 Mathf.PingPong 实际上是做什么的? 的相关文章

随机推荐