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
0
Question by DeniedGames · May 10, 2013 at 05:34 AM · generationminecraftinfinite

Infinite Forest Generation

Hi, I am kinda new to Unity, started toying with it last year. I want to know how to make a infinte forest. Basically like how Minecraft loads a new chunk, with it's infinte generation. I am making a simple forest survival game, where you can only leave and finish the game once you have certain items. And you will have the option to stay in the forest, again, like Minecraft, with it's ending. Thanks!

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 fafase · May 10, 2013 at 06:14 AM

You could use that answer http://answers.unity3d.com/questions/21197/adding-trees-dynamically.html to place your trees by script

Now, Minecraft is not really infinite, it is just really big. It is not possible to make an infinite world with a computer. You would start to get unaccuracy due to float accuracy while reaching large position. Minecraft often has an ocean to stop you from going any further (note that I am not familiar at all with Minecraft).

To place your trees, you could do that randomly as well as your relief but that would mean that if you come back to the same point, it looks different. The solution is to use a hash function based on the position to return a value that will define where everything is placed. As it is based on the position when you come back to the same position, the function returns the same values and places the same environment.

Comment
Add comment · Show 4 · 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 DeniedGames · May 10, 2013 at 06:20 AM 0
Share

I hate the sound like a noob, but the second part just... I don't... what? I know what you mean, however the ocean in $$anonymous$$inecraft is very big, but eventually generates more land. Any chance of simple example script?

avatar image fafase · May 10, 2013 at 10:22 AM 0
Share

It is very big but it simply cannot be infinite.

A number in computer is either a float or a integer, they are limited because they are only 32bits they can at maximum represents a value of +4 billions (2 to the power of 32). Position are more likely to be float so without getting too deep that means among those 32 bits some are used for the decimal part.

As a result, you cannot access high values anymore, actually look at unity and make an object move in one direction non-stop, you will see a warning when it reaches about 10000. $$anonymous$$inecraft makes believe it is endless but they have to stop you from going in one direction or they load a new scene.

It is simply not technologically possible to recreate the universe in a computer.

For an example of hash function, well there are many of them, you could start learning about them http://www.cs.hmc.edu/~geoff/classes/hmc.cs070.200101/homework10/hashfuncs.html.

The most basic you could do is:

 int Hash(Vector3 pos, int valRange){
    float a = pos.x + pos.y + pos.z;
    a *=100; // This is just here to make it look more random
    a = $$anonymous$$athf.Round(a);
    return (int)a % valRange; // valRange is 2 so that you get 0 or 1
 }

The point of a hash function is to use some values to generate a result that seems to be random. It is like you give 1 and 2 and you get 25. Then 2 and 6 and you get 10. But if you enter again 1 and 2 you get 25 again. So it is not random.

In my example, whatever values you pass, you get 0 or 1 that you can use for tree or no tree.

You could tile your map with tiles so that you only perform the function every 1m to avoid getting trees too close or on top of each otheralt text

présentation1.png (5.2 kB)
avatar image DeniedGames · May 11, 2013 at 12:00 AM 0
Share

So far I just made a huge terrain and used the biggest tree brush, with variant settings. Still took 10 $$anonymous$$utes to finish it.

avatar image fafase · May 11, 2013 at 07:49 AM 0
Share

Fact is even though you could use the Hash function to put trees or not, you would have to access the terrain data to place the trees.

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

14 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

Related Questions

map generation issues 0 Answers

Voxel based Terrain generation. Pointers please. 2 Answers

Minecraft (Cube) Terrain 1 Answer

Object Refrence Not Set To An Instance Of An Object? 2 Answers

This script really makes my game lag! 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