如何在使用 Transform.RotateAround 时使用指数缓动函数?
我有一个场景,其中一个立方体形状的物体在平坦的表面上“滚动”。每次,它都会在 pivotAxis
(垂直于运动方向)上围绕 pivotPoint
(与表面接触的边缘)完成 90 度旋转。为此,Transform.RotateAround 函数似乎很合适,因为它允许我提供这些参数并应用这种偏心旋转带来的必要位置变化。该运动的时间限制为totalDuration
。
这是在应用运动的协程内部:
timePassed = 0f;
while (timePassed < totalDuration)
{
timePassed += Time.deltaTime;
rotationAmount = (Time.deltaTime / totalDuration) * 90f;
cube.RotateAround(pivotPoint, pivotAxis, rotationAmount);
// Track rotation progress in case the function is interrupted
offBalanceDegrees += rotationAmount;
yield return null;
}
// snap position and rotation of cube to final value, then repeat
这工作得很好,并且给了我线性运动,因为每次迭代中的旋转量是相同的。但是,我希望它具有缓动功能,可以缓慢开始并快速完成。我仍然必须能够指定 pivotPoint
、pivotAxis
和 totalDuration
,但我对如何实现这一点有点困惑。
我见过的其他示例围绕对象中心进行旋转,这比我的情况更简单。
I have a scene where a cube-shaped object "rolls" on a flat surface. Each time, it completes a 90-degree rotation around pivotPoint
(the edge making contact with the surface) over the pivotAxis
(perpendicular to the direction of movement). For this, the Transform.RotateAround
function seemed appropriate, as it allows me to supply those parameters and apply the necessary position change that comes with this kind of off-center rotation. The movement has a time constraint of totalDuration
.
This is inside the coroutine where movement is applied:
timePassed = 0f;
while (timePassed < totalDuration)
{
timePassed += Time.deltaTime;
rotationAmount = (Time.deltaTime / totalDuration) * 90f;
cube.RotateAround(pivotPoint, pivotAxis, rotationAmount);
// Track rotation progress in case the function is interrupted
offBalanceDegrees += rotationAmount;
yield return null;
}
// snap position and rotation of cube to final value, then repeat
This works well enough and gives me linear movement, as the rotationAmount
in each iteratio is the same. However, I'd like this to feature an easing function to start off slowly and finish quickly. I must still be able to specify a pivotPoint
, pivotAxis
and totalDuration
, and I'm a bit stuck as to how I could accomplish this.
Other examples I've seen applied rotation around the object's centre, which is a simpler case than what I have.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果您的线性
t
介于 0 和 1 之间,则可以使用tnew = t * t * t;
获得三次方tnew
。然后,您只需重新配置方程以使用从 0 到 1 的t
。总而言之,这可能如下所示:
If you have a linear
t
between 0 and 1, you can usetnew = t * t * t;
to get a cubictnew
. Then you just need to reconfigure your equation to use at
that goes from 0 to 1.Altogether, this might look like this: