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 $$anonymous$$ · Apr 04, 2012 at 06:15 PM · randomgenerationrandomizegenerated

Randomly generated/ procedurally generated world

Hi guys, I'm relatively new to untiy, I know some of the basics and I have barely begun to learn java (but I am, its a work in progress), and I was wondering if any of you knew how I could make randomly generated terrain, like in minecraft. Now I know what your thinking, I want to make a minecraft clone, but no, I just want a randomly generated world. I dont even want it to be cubes, just normal unity terrain, but created randomly. Thanks guys Tom

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
2

Answer by Rabbit-Stew-dio · Apr 04, 2012 at 11:22 PM

Have a look at the "Terrain Toolkit" Unity offers as add-on.

It contains the standard algorithms (Perlin noise, etc) to build terrains. It comes with full source code and is a good way to start experimenting. The way the toolkit manipulates terrain objects in the editor can easily be used when the game is running.

Once you have one terrain up and running, you just have to create terrain objects on the fly, position them and then connect them with their neighbouring terrains. If you make a large world, then you will have to destroy terrains that are out of scope, or you run out of memory pretty soon.

This paper gives you a great overview on how to produce a terrain, the techniques and what is working and what is not working. In combination with the terrain toolkit sources, you can't go wrong.

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 PsychoticBob · Dec 03, 2012 at 08:04 PM 0
Share

But how do you actually do that? What do you put in the script editor to make it do a new terrain get generated when you are in a certain position?

avatar image Rabbit-Stew-dio · Dec 03, 2012 at 09:08 PM 0
Share

In my code, I have an active set of a few terrains (25 -> 5 x 5). Each terrain is 500m x 500m in side.

Now I can compute what set of terrains I need by taking my camera's position divided by 500. That gives me a terrain-index in a grid.

  terrain_grid_x = (int) Camera.main.transform.position.x / 500;
  terrain_grid_y = (int) Camera.main.transform.position.z / 500;

When you leave your current terrain cell (the new terrain_grid_x is different from the old one), you can move the existing terrains that are still visible on their new positions, and then you generate the new terrains for the now empty cells.

Lets assume my terrains have the numbers, and lets say I have 9 terrain cells. The central terrain '5' is where your character is walking on. The terrains around it make sure that you do not see empty space when the camera looks at the horizon.

   1   2   3
   4   5   6
   7   8   9

When my character moves downwards, he would cross from terrain 5 to terrain 8. At that point, I move the terrains that are still visible around, so that my character is still centred. So the row "4 5 6" moves into the first row, and row "7 8 9" moves into the centre row. The whole terrain grid now looks like this:

   4   5   6
   7   8   9
   -   -   -

Now generate the missing terrains and after a while, your character is happily walking again.

(I use a 5x5 grid so that I can generate the terrains in the background. The terrain generation time is far less than the time needed to walk from the top edge to the bottom of the centre tile.)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Make sure objects are not instantiated on each other 2 Answers

Randomly Generated Levels 3 Answers

Random 2D Face Generator 1 Answer

How to create a perlin noise heightmap with the values being the highest around a point? 1 Answer

Random code generation 3 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