我有一個場景,一個立方體形狀的物體在平面上“滾動”。每次,它圍繞pivotPoint(與表面接觸的邊緣)在pivotAxis(垂直于運動方向)上完成 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
這作業得很好并且給了我線性運動,因為rotationAmount每次迭代都是一樣的。但是,我希望它具有緩動功能,可以緩慢開始并快速結束。我仍然必須能夠指定一個pivotPoint,pivotAxis和totalDuration, 并且我對如何實作這一點有點困惑。
我見過的其他示例圍繞物件的中心應用旋轉,這比我所擁有的更簡單。
uj5u.com熱心網友回復:
如果你有一個t介于 0 和 1 之間的線性,你可以tnew = t * t * t;用來得到一個三次tnew。然后你只需要重新配置你的方程以使用t從 0 到 1 的 a。
總而言之,這可能看起來像這樣:
timePassed = 0f;
offBalanceDegrees = 0f;
while (timePassed < totalDuration)
{
timePassed = Time.deltaTime;
float t = timePassed / totalDuration
t = t * t * t;
// Track rotation progress in case the function is interrupted
oldRotationAmount = offBalanceDegrees;
offBalanceDegrees = t * 90f;
cube.RotateAround(pivotPoint, pivotAxis, offBalanceDegrees - oldRotationAmount);
yield return null;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/440952.html
