我有一些行星周圍產生的宇宙飛船。我想讓他們在這個星球上飛翔。旋轉宇宙飛船,面對給定的方向矢量
我也希望他們旋轉,他們正在飛行。因爲此刻,組合屋只是其初始旋轉方向。
我不知道,如果transform.RotateAround();
就是拿這個問題的正確的。 Transform.Rotate()
不起作用。
所以我的問題是,怎樣才能讓我的飛船飛周圍的行星和旋轉到它們飛行的方向?
這裏是我到目前爲止的代碼:
Transform planet; // The planet to fly around
float speed = 5; // The movementSpeed
Vector3 flyDirection; // The direction, it flies around
void Start()
{
planet = GameObject.FindGameObjectWithTag("Planet").transform; // Get the transform of the planet
Vector3[] directions = { Vector3.left, Vector3.right, Vector3.up, Vector3.down }; // The possible directions to fly
flyDirection = directions[Random.Range(0, directions.Length)]; // Get a random fly direction
}
void Update()
{
transform.RotateAround(planet.position, flyDirection, speed * Time.deltaTime); // Fly around the planet
transform.Rotate(..); // Rotate the Object to the fly direction
}
呃......澄清,是transform.RotateAround()'爲你工作',或者是,只要你想要麼不工作? – Serlite
嘿,我真的不知道......對象正在飛來飛去,但他們並不繞着地球旋轉。他們都在東部隨機飛行... – Garzec