我有一些行星周围产生的宇宙飞船。我想让他们在这个星球上飞翔。旋转宇宙飞船,面对给定的方向矢量
我也希望他们旋转,他们正在飞行。因为此刻,组合屋只是其初始旋转方向。
我不知道,如果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