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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
2
Question by OxenEknat · Jun 11, 2014 at 10:26 AM · activeinactiveinfinite terrain

How can I generate an infinite world as the player walks through it?

I've made a prefab wich generates other prefabs, to make a terrain. Now, I need to make this terrain infinite. What I thought of is to make a script that creates automatically the prefab-making prefab, but, to make the game not create the entire world once, I need to know if I can create an inactive by default prefab, and activate it only if it is in a range chosen by me or the player. Is it possible?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Tarlius · Jun 12, 2014 at 08:13 AM

You can't create an infinite world by instantiating inactive prefabs. You would need a (smaller) infinite number of them!

You'll probably want to make an algorithm that will generate terrain of a certain square size (which it sounds like you might have done already), and add (and remove!) them as the player moves around. Do not forget the remove part! ;)

A lot of open world games take this kind of approach (although typically they load data rather than generate it, of course)

Depending how big/detailed they are, you'll probably want at least 9 active at a time. One in the centre, 4 direct adjacents and 4 diagonal adjacents.

If you want to make all players have the same "random" world, you can set the seed for the random number generator you use to build the world.

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 OxenEknat · Jun 12, 2014 at 08:12 PM 0
Share

$$anonymous$$aybe I didn't explain well what I meant: the map/chunk-making prefab should have a code that generates the same prefab on the 9 squares you talked of above. Although, now I find some things that will, according to $$anonymous$$urphy's laws, go wrong. Now I found a great tutorial to explain how to make the chunks, but I can't understand how can I make the game create chunks automatically. $$anonymous$$aybe using the distance between the player and the corner of the chunks? (Forgive grammatical errors, English is not my first language)

avatar image oasisunknown · Jun 12, 2014 at 08:38 PM 0
Share

You could probably check the players distance from the center of the chunk and if he is a certain distance away then generate the next chunk.

avatar image OxenEknat · Jun 12, 2014 at 08:50 PM 0
Share

Yes, you're probably right.

avatar image Hamsword · Jul 25, 2020 at 05:30 PM 0
Share

How would someone go about creating a script that does this? I'm trying to achieve the same exact thing but I don't know how I could do it.

avatar image
1

Answer by stuart6854 · Jun 12, 2014 at 08:18 PM

I have semi-infinite terrain generation(almost infinite) and the way i surround the player in them is at the start i make the first 9 tiles or so. Then when the player steps onto on one of those tiles the game will search in the 9(or so) tiles around that tile and if their is empty space it will create a new one.

Hope it makes sense.

Comment
Add comment · Show 3 · 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 stuart6854 · Jun 12, 2014 at 08:28 PM 0
Share

Point to add:

I use a function to find the closest tile/chunk using vector2.distance(NOT vector3) but make sure your using the center of the tile/chunk for the distance

avatar image OxenEknat · Jun 12, 2014 at 08:42 PM 0
Share

Yeah, it makes sense... maybe I'll try to do that with chunks, because using small tiles you can see lots of them. You can use nine tiles if you make something in the dark, like Slender, making the farthest fading to black. Thanks a lot! Edit: I've seen your comment just now... why Vector2 and not Vector3?

avatar image stuart6854 · Jun 12, 2014 at 09:12 PM 0
Share

its up to you but in my game i use vector2 because i dont want to take into fact how high/low the player is just the how far away he is on 2d plane.

avatar image
0

Answer by sradomski · Feb 09, 2016 at 05:12 PM

We have created thousands (>100k) of Unity terrains with different levels of detail from the SRTM data at NASA. There is a video of an interactive fly-over with 1/4th of the data at youtube, and another one with full resolution and an interpolated camera path. Frame-rate of the first video is slower as we calculate splatmaps dynamically, they are pre-calculated in the second video.

The challenge is the sheer size of it. Unity will throw warnings if you have any coordinates >100k and for a convincing impression and actual "walk-size", you'd need a size of 40.000.000 x 20.000.000. As such, you need to move the terrain under a camera fixed at (0,0,0), but this will complicate the placing of any other object.

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 JackTheKreator · Apr 14, 2016 at 07:16 PM 0
Share

You could parent the objects to the chunks. Then they would move with them.

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

27 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

Related Questions

Help Activating/Deactivating all Game Objects with same tag 1 Answer

Best way to keep track of inactive GameObjects? 1 Answer

Activate gameobject that is deactivated with c# 2 Answers

How to find Inactive GameObject 16 Answers

GameObjects deactivate when Unity starts 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