【发布时间】:2018-12-06 14:05:24
【问题描述】:
我编写了以下方法,在一段时间内将任意点围绕另一个任意点旋转一个角度。有问题的点现在移动不规律,但最终在我认为是理想目的地的地方结束。我需要让它平稳地移动到这个角度。
请注意,积分与游戏对象无关。
从下图中,我试图在给定的时间段内将贝塞尔曲线的一个点(用LineRenderer 绘制)围绕另一个点移动一个角度。这些点都不与包含贝塞尔曲线的游戏对象的位置重合。
IEnumerator runMovement() {
yield return new WaitForSeconds(2.0f);
Vector2 pivot = points[3];
StartCoroutine(RotateControlPointWithDuration(pivot, 2.0f, 90.0f));
}
IEnumerator RotateControlPointWithDuration(Vector2 pivot, float duration, float angle)
{
float currentTime = 0.0f;
float ourTimeDelta = 0;
Vector2 startPos = points[0];
ourTimeDelta = Time.deltaTime;
float angleDelta = angle / duration; //how many degress to rotate in one second
while (currentTime < duration)
{
currentTime += Time.deltaTime;
ourTimeDelta = Time.deltaTime;
points[0] = new Vector2(Mathf.Cos(angleDelta * ourTimeDelta) * (startPos.x - pivot.x) - Mathf.Sin(angleDelta * ourTimeDelta) * (startPos.y - pivot.y) + pivot.x,
Mathf.Sin(angleDelta * ourTimeDelta) * (startPos.x - pivot.x) + Mathf.Cos(angleDelta * ourTimeDelta) * (startPos.y - pivot.y) + pivot.y);
yield return null;
}
}
【问题讨论】:
-
我建议您添加动画 gif 或链接到显示您当前问题的视频。此外,最好添加另一个视频来显示您正在尝试做什么
-
另外,听听@Programmer 所说的一切:)
-
@Fattie 我正在处理更新,很快就会准备好
-
@Programmer 我刚刚更新了问题
-
@Fattie 仍然有一些不稳定的动作。我刚刚更新了这个问题。老实说,我认为这个问题与您提供的链接有很多不同之处。