Question by
PhantomWalrus · Apr 05 at 09:13 AM ·
prefabsmove an object
How to make a Prefab move in the X and Z directions while also orbiting in a circular pattern?
I have C# experience but it's my first project in Unity. I'm making a 3D top-down Galaga-style space shooter. When I spawn in an "alien" it rotates in a circular pattern in the X and Z directions (I'm using Width and Height to make the orbit path the shape I want it to be), but it doesn't move around the screen in the X and Z directions while also orbiting like I want it to. It just spawns center screen and orbits the center position.
I used AddForce in the Start method to try to make this happen but no luck. Here's a portion of the code with which I can get the object to orbit, but not move around at the same time:
private void Start()
{
Rigidbody rigidBody = GetComponent<Rigidbody>();
rigidBody.AddForce(StartForce, ForceMode.Impulse);
}
void Update()
{
TimeCounter += (Time.deltaTime * Speed);
XCoord = Mathf.Cos(TimeCounter) * Width;
ZCoord = Mathf.Sin(TimeCounter) * Height;
transform.position = new Vector3(XCoord, YCoord, ZCoord);
}
Comment
Your answer