0

自从我尝试用统一引擎创建一个轨道系统以来已经有一周了。我找到了不同的解决方案和方法,但它们不能满足我希望看到的结果。有人能告诉我如何创建一个 C# 脚本并添加其他细节,例如偏心度吗?

这是我的“最佳”和最新代码:

轨道.cs

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

4

0 回答 0