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 juliobds · Jul 08, 2011 at 12:20 PM · runtimeheightmapruntime-generationprocedural-terrainmodification

Modifying an heightmap at runtime

Hi,

I've been working on a procedural terrain generator. I first create the heightmap than I apply it to a terrain data object. My problem is the following: I can't seem to understand how to modify the heighmap.

     private float[,] GenerateHeightmap(float[,] heightMap, Vector2 arraySize) //A flat heightmap is received here and the arraysize contains the x and y of the heightmap
 {
     for (int My = 0; My < arraySize.y; My++) {
         for (int Mx = 0; Mx < arraySize.x; Mx++) {
             heightMap[Mx, My] = (float)(Mx / 1000);//Because my heightmap is 513x513 I'm just making sure the value of heightMap[Mx, My] is under 1
         }
     }
     return heightMap;
 }
 //After receiving the heightmap I do:
 terData.SetHeights(0, 0, heightMap);
 //I think everything should be running fine but it isn't. 




The problem is that I don't see any modifications on the terrain. Am I missing something? At the moment I just want to modify the heightmap and see those modification in the terrain.

Plus, can anyone explain to me better why the range between 0 and 1 for the heightmap???

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by DaveA · Jul 08, 2011 at 02:07 PM

Mx is an int, Mx/1000 is gonna be zero all the time. Try ((float)Mx / 1000.0f) I don't know why they clamp it to 0,1, but you can scale Y. Find your min/max height and scale accordingly.

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 Joshua · Jul 08, 2011 at 02:11 PM 0
Share

How often fractions with ints have kicked me in the face..

avatar image juliobds · Jul 08, 2011 at 04:42 PM 0
Share

Thank you so much... I spent the ENTIRE night trying to figure it out.

avatar image
0

Answer by AyeJayCee · Oct 15, 2014 at 12:39 PM

The heightmap is a bitmap with 0 for black and 1 as white. It's then multiplied by your heightmap height value for scale. When editing the heightmap procedurally you might as well ignore the scale as it's only used at the end.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Gradual Terrain Smoothing from a Flat Area (at Runtime) 0 Answers

Occlusion culling world generation runtime 0 Answers

ios runtime gameobjects not showing up 0 Answers

How to instantiate prefabs in an unloaded (or just loaded) scene? 1 Answer

Overwriting a prefab in runtime? 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