• 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 Spracky · Apr 06, 2016 at 05:09 AM · c#unity 5terrain gen

Generate a plane and apply an heightmap at runtime?

So I know this is a loaded question, but is it possible to create a plane and apply a randomly generated heightmap at runtime to make terrain? I've done a lot of searching and nothing really helps. Also, would it be possible to make the plane triangulated and low poly like in this video?

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

Answer by taxvi · Apr 06, 2016 at 08:32 AM

Generate a plane:

yes you can generate any kind of mesh at runtime. Take a look at the Mesh Class

You generate a mesh by:

  • creating array of Vector3 representing positions of vertices. Assign it to the Mesh.vertices

  • then create an array of integers that will represent your faces. In graphics all the faces are triangles (even though some 3D editors couple them into quads). The int array must contain the indexes of vertices. 0,1 and 2 in that array will be a face connecting the corresponding vertices. 3,4 and 5 will be the second face, etc. So the length of the array should be a multiple of 3. Also note that the vertices should be ordered clockwise to correctly generate the face normal. E.g: if 0-1-2 face has its normal pointing up than 0-2-1 face will have a downward normal. This is necessary to correctly let shaders reflect light and other stuff.

  • After you're done call mesh.RecalculateBounds, otherwise the camera will occlude it incorrectly (objects outside the view spectrum are not rendered. camera decides if the object is in view spectrum by using the mesh bounds). This command sets the bounding box of the object. Bounding box is the smallest box in which the object fits in (calculated in local space).


Apply heightmap at runtime:

Take a shader with heightmap and assign to your mesh.

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 Spracky · Apr 06, 2016 at 04:01 PM 1
Share

Thank you very much! Now I just need to go find out how to generate a heightmap at runtime.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Enemy Ai is not working as planned 0 Answers

How to Spawn after checking if the clones are destroyed. 1 Answer

My sphere is not moving in the unity? 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