Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I dont' use unity, but I think this problem isn't unity/c# specific.</p> <p>You can implement it considering that every planet you want to place "depends" from a parent, someway, sun excluded and placed at origin.</p> <p>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 it's 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...</p> <p>With this simple scheme, you always have to manage 4 things which can be easly implemented as a class, i.e (not tested, I wrote it here without a compiler, check it from possible syntax errors):</p> <pre><code>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 } } </code></pre> <p>More, you can easly implement sun, planets, moons, moons of moons :-)</p> <p>Every time you create a planet, you will assign its parent, randomize class values taking care only of OrbitRadius >> Radius (>> I mean really "really greater", not just "greater")</p> <p>This should also give you a strongest "planet chain" to deal with, maybe with recursive functions.</p> <p>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 loose with scale factors.</p> <p>Hope this helps</p> <p><strong>edit</strong>: I added a sort of CalculatePosition, can't verify it now, It's only there to clarify the concept and can be surely improved.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload