Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:56:25+00:00 2026-06-14T19:56:25+00:00

I’m making a game which has multiple planets. Now I want to randomly generate

  • 0

I’m making a game which has multiple planets. Now I want to randomly generate their position, so I need to make sure they aren’t too close to each other so they don’t collide, neither too far away from each other since you should be able to see them all.

Each planet has a radius, so the distance between each planet should be: it’s own radius + the radius of any other planet + a small offset. Also it would be nice if they aren’t too far away from each other, as close as possible.

I just start with placing the first planet at 0,0,0. Then the second is easy to calculate (just a random direction and then the distance). The third also is doable, though after that I’m stumped.

How can I make a start? I’m using Unity, so the position is a Vector3, and I’m working in C#.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:56:27+00:00Added an answer on June 14, 2026 at 7:56 pm

    I don’t use unity, but I think this problem isn’t unity/c# specific.

    You can implement it considering that every planet you want to place "depends" from a parent, some way, sun excluded and placed at origin.

    So said, sun it’s located at (0,0,0), Planet1 belongs from sun and it’s located at certain radius distance, so it has its own radius and a rotation angle (always related to its parent). Planet 2 may have sun as parent, so it’s a "planet", or from Planet1, becoming its moon.
    And so on…

    With this simple scheme, you always have to manage 4 things which can be easily implemented as a class, i.e (not tested, I wrote it here without a compiler, check it from possible syntax errors):

    public class Planet
    {
      public Planet Parent;     //if null, I'm the first in chain
      public float OrbitRadius; //From my parent
      public float OrbitAngle;  //0-360 around my parent
      public float Radius;      //Planet size
    
      //EDIT:
      public Vector3 Position;
    
      public void CalculatePosition()
      {
        if(Parent == null) this.Position = new Vector(0, 0, 0);
        this.Position = Parent.Position + OrbitRadius + Math.Sin(OrbitAngle * Math.PI / 180.0f);  //Check if it has to be done for each vector component
      }
    
    }
    

    More, you can easily implement sun, planets, moons, moons of moons 🙂

    Every time you create a planet, you will assign its parent, randomize class values taking care only of OrbitRadius >> Radius (>> I mean "really greater", not just "greater").

    This should also give you a strongest "planet chain" to deal with, maybe with recursive functions.

    As final step, you can "render" their positions walking all the chain, going to add PlanetX position to parent’s position(s) in an incremental manner, dealing only to OrbitAngle; you need some Sin/Cos math here but you will not lose with scale factors.

    Edit

    I added a sort of CalculatePosition, can’t verify it now, It’s only there to clarify the concept and can be surely improved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.