【发布时间】:2021-03-02 17:04:36
【问题描述】:
我正在尝试围绕目标行星(目前只是一个圆圈)移动和旋转一些云。我降低了动作,但我真的在旋转部分苦苦挣扎。我希望它与它在圆圈上的位置成比例旋转,但我一直试图猜测正确的数字。代码如下:
public class CloudMovement : MonoBehaviour
{
public GameObject target;
private float RotateSpeed = .05f;
private float Radius = 1.0f;
private Vector2 center;
private float angle;
private void Start()
{
center = target.transform.localPosition;
Radius = target.transform.localScale.x / 1.5f;
}
private void Update()
{
angle = angle + RotateSpeed * Time.deltaTime;
this.transform.Rotate (Vector3.forward * -angle * Time.deltaTime);
Vector2 offset = new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)) * Radius;
this.transform.position = center + offset;
}
}
【问题讨论】: