Public Group

# Initial positions for orbiting satellites

## Recommended Posts

Hello

I wonder if someone could point me to the right direction.

I have the following script, which I use to add objects as orbiting satellites for a host object:

using UnityEngine;

public class Satellite : MonoBehaviour
{

public GameObject host;
public float orbitSpeed = 5f;

private Vector3 center;
private float angle;

private void Start()
{
center = new Vector3(host.transform.position.x, host.transform.position.y, 0);
}

private void Update()
{

angle -= orbitSpeed / radius * Time.deltaTime;

transform.position = center + offset;
}
}

Now when I create these object, I randomize the radius and it works fine. However, their initial positions are always like this:

How could I set their initial position to be something else? Any help would be appreciated.

- Barra

##### Share on other sites
Posted (edited)

Randomize an initial angle, and compute the initial x & y coordinate from it.

Edited by Alberth

##### Share on other sites

Thanks Alberth for the simple solution!

So I was obviously greatly overcomplicating the issue.

• 17
• 19
• 23
• 10
• 10