Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Chimera3D · Jun 24, 2013 at 08:50 PM · proceduralgeneratefieldsquares

Procedurally Generate Field of Squares

I'm not sure at all how to go about this but what I want to do is generate a field of squares of random sizes but all fit within an allotted area (a larger square). The meshes generated are supposed to be planes but have to fit within a larger invisible plane, how can I go about doing this?

EDIT: Is there a way I can hold an array of arrays of Vector2's (the arrays of Vector2's would hold the four vertices of the squares, and the larger one all of the squares, that way I can check what positions for new vertices are available and which aren't)?

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

Answer by slayer29179 · Jun 24, 2013 at 09:25 PM

Why not use an Integer or Vector2 for the size of the larger square and add the random X and Y size to each number. For example:

 int large_size_x = 0; //Lets say your large grid is 30 in size
 int large_size_y = 0;
 
 if (large_size_x < 30 && large_size_y < 30)
 {
     var xNum = Random.Range(1, 20); //Size of the actual grid
     var chosenx = xNum; //Add the size of your smaller grid to the large overall variable.
     
     //Spawn your grid here and use local transform to edit the size
     var small_grid = Instantiate (gridObject, transform.position, Quaternion.identity);
     large_size_x += chosenx;
     small_grid.transform.position.x += chosenx;
 }

Not Tested

Hope this gives you some grounds to go off :)

Comment
Add comment · Show 2 · 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 Chimera3D · Jun 25, 2013 at 03:36 AM 1
Share

The main problem though is making sure the sizes of all of the squares fits within the larger area and also making sure they don't overlap, but thanks.

EDIT: Or maybe I was a bit confused as to what you were trying to say.

avatar image slayer29179 · Jun 25, 2013 at 05:25 AM 0
Share

I think you may be confused :)

The two top large_size variables are there as the overall size of all your small grids added up.

And then you use the If statement against the two large_size variables to deter$$anonymous$$e what size you have now.

Every time you spawn you increase the variables by the size of the grid.

For example, if I spawned a grid which was 5x5. I would increase large_size_x and y by 5 each. Then I would keep increasing until I reached 30 on my large_size_x and y.

I hope this explains it slightly better :)

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to instantiate prefabs between 2 objects like a path 0 Answers

How do I generate believable terrain for a 2D game using cubes? 1 Answer

How to generate terrain for 2d up scroller game ? 0 Answers

Procedurally generating terrain? 0 Answers

Procedural materials for cloud formations? 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