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 Axil · Sep 05, 2012 at 04:29 PM · terrainrandomruntime

Semi-Random terrain generated at runtime.

Hi. I need a terrain tool (or tools) capable of generating random terrain with some fixed features. Like flat areas to facilitate building cities, at certain spots on the map.

There seem to be a lot of tools that can randomize terrain to then be saved as a fixed terrain object, but i want this to happen every time a new map loads in the game.

Thanks.

~Axil

Comment
Add comment · Show 2
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 Axil · Sep 05, 2012 at 06:25 PM 0
Share

Yeah it appears as though the terrain toolkit can randomize the map like i need. I'm just not sure if it, or any other tool can take that random map, and modify it to add some flat areas in set positions..

I would think that if you have the capability to generate the random map, a second pass that added some static features should be possible using the same kinds of methods, no?

avatar image Axil · Sep 05, 2012 at 08:35 PM 0
Share

I feel like my lack of experience in this area is making my question vague, and harder to answer than it needs to be.

Let me try and summarize what i want to do in a little more detail.

  1. After the game has loaded, but before the player enters the map, i want a random terrain of a set size generated. I would like to be able to utilize a tool with features like Terrain toolkit has, where the randomization is done in such a way to make believable hills, mountains, valleys, etc, within ranges set by me.

  2. again before the player enters the game, i want that random map to be modified so that i can add flat places on certain portions of that map, by x,y,z, coordinate. I need these places to be flat so i can put prefab structures on them during the course of the game. In doing so, the height of the terrain has to be taken into consideration somewhat, as a flat terrain at y=0, cored into a mountain would be unplayable.

$$anonymous$$aybe this isn't technically "run-time" generation? I don't need terrain popping up during game-play, i just want it to be randomized each time a map is loaded in, and still have the control to make certain sections of the map "unrandom".

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Eric5h5 · Sep 05, 2012 at 11:04 PM

You can generate any kind of terrain you want, and do anything with the results. What you're doing is generating a 2D array of floats to use for the heightmap, so you can make flat areas just by writing the same value to a given area of the array. Here's an incredibly cheesy "random terrain generator" that makes some random bumpy ground, with some randomly-positioned flat areas:

 function Start () {
     var res = 513;
     var tData = GetComponent(Terrain).terrainData;
     tData.heightmapResolution = res;
 
     var heights = new float[res, res];
     for (var i = 0; i < res*res; i++) heights[i%res, i/res] = Random.Range(.49, .51);
     tData.SetHeights (0, 0, heights);
     
     var flat = new float[50, 50];
     for (i = 0; i < 50*50; i++) flat[i%50, i/50] = .5;
     for (i = 0; i < 10; i++) {
         tData.SetHeights (Random.Range(0, res-50), Random.Range(0, res-50), flat);
     }
 }
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
avatar image
0

Answer by Owen-Reynolds · Sep 05, 2012 at 06:53 PM

From a programming side, a random terrain generator doesn't care it you run it on level load, or in the editor. At some point it's going to make a 2D height map, and another with the texture values, which you can do use however you want. So, you should be able to reuse any random terrain code you already have.

But real-time random terrain is a lot of work. Off-line, a human can run one, then clean up the impossible-to-play/boring/dumb-looking parts. Look at random dungeons -- they have all these 2x2 "rooms", crazy long winding hallways, "level is one giant room" levels (really 8 rooms that got randomly jammed together.)

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

9 People are following this question.

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

Related Questions

Changing Replacement Shaders at Runtime 2 Answers

Modify a mesh at runtime 0 Answers

Procedural Terrain? 3 Answers

Need help with randomizing starting location of terrains 0 Answers

Paint Terrain Texture From Vector3 List 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