Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by D3mon1zA · Jul 09, 2016 at 02:37 PM · proceduralprocedural-generationplanetaryuniverse

Procedurally generated (Small)Universe

Hi, I am working on an rpg space based game and I want to procedurally generate the unverse for reasons of efficiency. Here is my script so far it's pretty basic but is working kind of... the issue I am having is when it randomly spawns a star it is ment to spawn a random amount of planets like a solar system. but when I run game everything spawns ok except the planets spawn from the point of the empty gameobject the script is attached to (as a child of it's "host Star") I have tried running 2 different scripts one to spawn the stars and then each star with a script to spawn the planets but both ways run into the same problem..... public GameObject Seed; public int SpacingMax = 50; public int SpacingMin = 25; public int ScaleMax = 10; public int ScaleMin = 5;

 void Start ()

{ int size = Random.Range(5, 10); float[,,] SpaceTime; SpaceTime = new float[size, size, size];

     for (int a = 0; a < SpaceTime.GetLength(0); a++)
     {
         for (int b = 0; b < SpaceTime.GetLength(0);b++) 
         {
             for (int c = 0; c < SpaceTime.GetLength(0); c++)
             {
                 SpaceTime[a, b, c] = Random.Range(0, SpacingMax);
             }
         }
     }
     for (int a = 0; a < SpaceTime.GetLength(0); a++)
     {
         for (int b = 0; b < SpaceTime.GetLength(0); b++)
         {
             for (int c = 0; c < SpaceTime.GetLength(0); c++)
             {
                 if (SpaceTime[a, b, c] >= SpacingMin)
                 {
                     int s1 = Random.Range(ScaleMin, ScaleMax);
                     int s2 = Random.Range(ScaleMin, ScaleMax);
                     int Scale = (s1 + s2) / 2;
                     int space = Random.Range(SpacingMin, SpacingMax);

                     GameObject UniVerse = (GameObject)Instantiate(Seed, new Vector3(a * space, b * space, c * space), Quaternion.identity);
                     UniVerse.transform.localScale = new Vector3(Scale, Scale, Scale);
                     UniVerse.transform.parent = this.transform;
                 }
             }
         }
     }
 }

}

what I would like to know is.. am I on the right track? if so anymore direction would be handy and if not what would be a better way to do this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by remption · Jul 10, 2016 at 09:43 PM

I'm thinking this has to do with the the fact that you're setting the planet's position in global space when you instantiate at line 23 (under assumption this is the planet you're instantiating - if not, the principal remains the same). Instead, when you make a new planet, you should:

1) set its transform's parent to the star it belongs to

2A) set its transform.localPosition to that vector you're using in line 23 new Vector3(a * space, b * space, c * space).

Local space for a transform means "relative to parent's transform". So, if your parent star is rotated or scaled, they will affect the planet's positioning when you use transform.localPosition to set it. So, alternatively to 2A for each planet, you can (and probably should) use:

2B) this.transform.position = this.transform.parent.position + new Vector3(a * space, b * space, c * space);

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image D3mon1zA · Jul 11, 2016 at 03:02 AM 1
Share

Thank you so much. Have resolved my problems by removing the transfom.position out of the main spawning script. and replaced it with a scrpt attached to the planet seeds int a = Random.Range(-$$anonymous$$Space, maxSpace); int b = Random.Range(-$$anonymous$$Space, maxSpace); int c = Random.Range(-$$anonymous$$Space, maxSpace);

     this.transform.position = this.transform.parent.position + new Vector3(a,b,c);

and works great still needs some tweaking but it works. Cheers

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UV problem on procedural mesh generation 1 Answer

Can't find a way to simplify this code... any help appreciated... 0 Answers

How to apply PBR material to Procedurally generated Mesh? 1 Answer

Procedurally generate 3D mesh from 2D image 1 Answer

Procedural Audio in 3D 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges