自从我尝试使用统一引擎创建轨道系统以来已经过去了一周。我找到了不同的解决方案和方法,但它们不满足我想要的结果。有人可以告诉我如何创建带有其他细节(例如偏心率)的C#脚本吗?
这是我的“最佳”和最新代码:
using UnityEngine;
using System.Collections;
public class Orbit : MonoBehaviour
{
public float axisX;
public float axisZ;
public float offsetY;
public Transform toOrbit;
public float vel = 0;
public bool clockwise;
float _vel = 0;
float timer = 0;
void Update () {
_vel = (vel / GetComponent<Rigidbody>().mass)*Time.fixedDeltaTime;
timer += _vel;
Rotate();
}
void Rotate() {
if(clockwise) {
float x = -Mathf.Cos(timer) * axisX;
float z = Mathf.Sin(timer) * axisZ;
Vector3 pos = new Vector3(x, offsetY, z);
transform.position = pos + toOrbit.position;
} else {
float x = Mathf.Cos(timer) * axisX;
float z = Mathf.Sin(timer) * axisZ;
Vector3 pos = new Vector3(x, offsetY, z);
transform.position = pos + toOrbit.position;
}
}
}
PS :我正在使用Unity 5.2