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 Rosscoe3 · Sep 09, 2015 at 08:45 PM · randomproceduralspawner

Random/Procedural Object spawner?

Hi.. im trying to basically fill this plane with grass/trees/brush and other things.. I've been looking up tutorials online and most of them have been on creating large worlds.. and not dealing with just objects.. I'm not sure if I use a texture or really how to go about this.. any help would be amazing!! alt text

screen-shot-2015-09-09-at-44225-pm.png (245.6 kB)
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
1

Answer by Orc_Horn_Productions · Sep 09, 2015 at 10:26 PM

Hi @Rosscoe3,

Depending on time constraints and budget you may benefit from buying something like MegaScatter:

  • https://www.assetstore.unity3d.com/en/#!/content/14954

Otherwise here's some ideas that'll hopefully point you in the right direction!

Research voxels:

  • http://forum.unity3d.com/threads/tutorial-c-voxel-terrain-with-infinite-terrain-saving-and-loading.293340/

To start add a material/texture to the plane with a normal map to create the illusion of a 3D grass (once you start placing objects on top it'll become less noticeable).

Create the assets you want to use and make a script to attach to all of them. This script can then use Foreach to add them to a List(), from there you can use random number generators (or seeds) to decide what gets instantiated. It's too far a complex topic for an answer here but I'll attach an extract from a script I use for some boids (NOTE: it is an extract and won't work if you copy it directly into your project). It's not quite the same but it's similar enough to give you a launching point for going forward!

As for terrain perlin noise is a fairly common way to randomly create a heightmap but it has it's shortfalls too - for example, in it's "basic" form you won't generate any caves.

Here's a link to a fairly interesting read as well on the topic of procedural generation:

  • http://pcgbook.com/

Obviously it's a large topic, open for a lot of discussion, so feel free to ask me anything else.

All the best!

EDIT: Please remember if this has been useful to upvote it :-)

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class ProceduralObsBoid : MonoBehaviour 
 {
     public static List<ProceduralObsBoid> boids;
     public static ProceduralObsBoid S;
 
     public List<ProceduralObsBoid> neighbours; 
     public List<ProceduralObsBoid> collisionRisks;
     public ProceduralObsBoid closest; 
 
     private void Awake()
     {
         if (boids == null) 
         {
             boids = new List<ProceduralObsBoid>();
         }
         boids.Add (this);
 
         S = this;
 
         neighbours = new List<ProceduralObsBoid> ();
         collisionRisks = new List<ProceduralObsBoid> ();
     }

     public List<ProceduralObsBoid> GetNeighbours(ProceduralObsBoid boi)
     {
         float closestDist = float.MaxValue;
         Vector3 delta;
         float dist;
         neighbours.Clear();
         collisionRisks.Clear();
 
         foreach (ProceduralObsBoid b in boids) 
         {
             if (b == boi) continue;
             delta = b.transform.position - boi.transform.position;
             dist = delta.magnitude;
             if (dist < closestDist)
             {
                 closestDist = dist;
                 closest = b;
             }
             if (dist < ProceduralLevel.S.nearDist)
             {
                 neighbours.Add (b);
             }
             if (dist < ProceduralLevel.S.collisionDist)
             {
                 collisionRisks.Add (b);
             }
         }
         if (neighbours.Count == 0) 
         {
             neighbours.Add (closest);
         }
         return (neighbours);
     }
 
     public Vector3 GetAveragePos (List<ProceduralObsBoid> someBoids)
     {
         Vector3 sum = Vector3.zero;
         foreach (ProceduralObsBoid b in someBoids) 
         {
             sum += b.transform.position;
         }
         Vector3 centre = sum / someBoids.Count;
         return (centre);
     }
 }









Comment
Add comment · 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

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

29 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 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

Overlapping Tile Generation 0 Answers

Procedural/Random Generation of Solar systems 2 Answers

Spawning an object at a random time | C# 2 Answers

Random 2D tile engine question 0 Answers

3D random level generation. 1 Answer


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