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 thijser · Mar 02, 2013 at 01:34 PM · positionnewbieheightmap

Heightmap to world location

Hello I'm trying to create a map generator. I already have a good height map but now I want to place items on the map. In order to do this I'm generating 2 random coordinates and look up the height in the height map. I think this should work however the height map uses coordinates between 1 and 0 were as the rest of the game uses number in the range of hundreds. How do I translate between the two?

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
0

Answer by aldonaletto · Mar 02, 2013 at 02:00 PM

This is too vague: is your height map being used to generate a terrain? If so, the code that generates the terrain should be examined in order to know how it translates map coordinates and the look up values to world space. You should post this code, or a link to it.

Anyway, the basic transformations are easy: you must defined the desired world sizes of your map in the world X, and Z axis. Supposing that your map should measure 1000 in the X and Z directions, and that the max height is 500, you could define the map scale in the appropriate fields in the script below, and get the height at some specific world position with the function GetHeight:

 var mapOrg: Vector3 = Vector3(-100, 0, -100);
 var mapSizeX: float = 1000;
 var mapSizeZ: float = 1000;
 var mapHeight: float = 500;
 
 function GetHeight(worldX: float, worldZ: float): float {
   var normX: float = (worldX-mapOrg.x)/mapSizeX;
   var normZ: float = (worldZ-mapOrg.z)/mapSizeZ;
   var normY: float = (get height map value at point x,z)
   return (normY*mapHeight)+mapOrg.y;
 }
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 thijser · Mar 02, 2013 at 06:17 PM

My code : [CODE]

 function Start () {

     var xRes = terrain.terrainData.heightmapWidth;
     var yRes = terrain.terrainData.heightmapHeight;
     var heights = terrain.terrainData.GetHeights(0, 0, xRes, yRes);
    

 
 var fxRes : float=xRes;
 var fyRes : float =yRes;
 //generate heightmap. 

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

10 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

Related Questions

Heightmap to world location 0 Answers

Camera rotation around player while following. 6 Answers

GUI To change with screen resolution? 2 Answers

Basics of procedural map generation 0 Answers

How to change a moving box's direction once it hits a point? 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