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 cj31387 · Mar 30, 2013 at 12:32 PM · terraingridcity

Basing a grid off the terrain in unity.

Would it be possible to make a grid based off the polygons of the terrain in unity? I want to make a city building game and start with roads being made off a grid, the best way I can think of doing that is basing it off each polygon on the terrain, but don't know how to do this yet. Can it be done and how would you basically go about doing that.

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
2
Best Answer

Answer by AlucardJay · Mar 30, 2013 at 04:30 PM

Yes, check all the terrain script on the Unity Wiki, all by Eric5h5, like I have found while using these for research myself. He Is .... Everywhere! (in a good way, I would be lost without his advice as found on all his answers and freely provided code. Thanks again Eric, you are a Legend). You would be wise to read his terrain scripts and learn from them : http://wiki.unity3d.com/index.php/Scripts/Editor

For more stuff you are looking at, watch quill18creates on YouTube : http://www.youtube.com/watch?v=dDqCPMpX1vI


Edit : Here's how to read the heights of the terrainData. Using this script as a reference : http://wiki.unity3d.com/index.php/RaiseHeightmap

 #pragma strict
 
 var myTerrain : Terrain;
 var myTerrainData : TerrainData;
 
 function Start() 
 {
     if ( !myTerrain )
     {
         myTerrain = Terrain.activeTerrain; // find the active terrain
     }
     
     myTerrainData = myTerrain.terrainData; // store the terrainData
     
     ReadTerrainAndPlaceCube();
 }
 
 function ReadTerrainAndPlaceCube() 
 {
     var heights : float[,] = myTerrainData.GetHeights( 0, 0, myTerrainData.heightmapWidth, myTerrainData.heightmapHeight );
     
     for ( var y = 0; y < myTerrainData.heightmapHeight; y ++ ) 
     {
         for ( var x = 0; x < myTerrainData.heightmapWidth; x ++ ) 
         {
             if ( x % 20 == 0 && y % 20 == 0 ) // place a cube every 20*20 units
             {
                 var actualHeight : float = heights[y,x] * myTerrainData.size.y; // need to multiply the height by the size.y of the terrain
                 
                 var cube : GameObject = GameObject.CreatePrimitive( PrimitiveType.Cube ); // create a cube
                 
                 cube.transform.position = new Vector3( x, actualHeight, y ); // position it at the actual height
             }
         }
     }
 }


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 cj31387 · Mar 31, 2013 at 08:12 AM 0
Share

Thanks those tutorials are awesome I'm learning a lot about scripting meshes but the wiki site you listed . The terrain scripts I see don't look like they would show data of terrain objects to base a grid off of. which one were you talking about specifically? Also modifying the 2d Tilemap script seems like a good place to start.

avatar image AlucardJay · Mar 31, 2013 at 08:34 AM 0
Share

I have edited my answer to show how to read the heights at a position, calculate the actual height based on the terrainData.size , then place a primitive cube at that position. Hope you like it =]

avatar image nasa8 · May 27, 2013 at 05:00 PM 0
Share

I've tried to create such a cube map for a terrain of 256x256 elements. I got 999+ messages that I have too many rigid objects or colliders. So, how many collider may I put in one scene?

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

13 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

Related Questions

Push into Two-Dimensional Array 2 Answers

The best way to draw grid on terrain in editor mode 0 Answers

how to produce endless terrain illusion? 1 Answer

What is the best way to make modular (selectable squares) terrain? 2 Answers

How can I display the grid so I can see it on my terrain? 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