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 nical · Sep 16, 2011 at 04:13 PM · terrainheightmap

Overlapping terrains

Hi,

I am experimenting with having multiple overlapping terrains the idea is to have one representing the ground and another one for the water with some simplistic flow dynamics computed in realtime.

This doesn't have to be optimized, it is just some kind of prototype to experiment with what it can bring in term of gameplay.

The thing is that I don't really get how to access the different height maps from the script. I've seen code snapshots on the internet where people are using Terrain.activeTerrain, but it doesn't let me access the two separate height maps (actually it only give me access to the ground terrain, not the "water").

I am new to Unity but I get the feeling that the engine automatically splits the Terrain in smaller terrains for performances and gives you access to the most relevant "sub-terrain" with Terrain.activeTerrain (I know I might be totally wrong though) but what i need is several overlapping layers...

How can I access two different overlapping heightmaps at the same time from script? Or is it that I should use another kind of primitive, like something that would not be a terrain object but would still follow a heightmap's deformations?

Thanks in advance,

Nicolas

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 syclamoth · Sep 16, 2011 at 04:51 PM 0
Share

If performance is not a big issue, and you plan on doing it all procedurally anyway, why don't you just cut out the middleman and generate a mesh entirely from scripts? The only things the terrain editor really gives you are nice brush tools and the ability to place detail objects/trees- neither of which you need.

avatar image nical · Sep 27, 2011 at 05:16 PM 0
Share

Ok thank you, This what I am trying to do right now. Is it possible to choose the number of subdivisions of the default plane object or do I need to generate the vertices by hand ?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by msknapp · Sep 27, 2011 at 10:11 PM

I don't recommend using a different primitive. Performance will be better if you use Terrain objects.

One weird thing I figured out is that Terrain extends Component, meaning it is not itself a type of game object, but a member of a game object instead. In the Terrain class you can get a reference to the TerrainData it is using with "myTerrain.terrainData". Then you can get a reference to the heightmap with:

 // (Please forgive the C#, hope you can translate to javascript if necessary)
 Terrain[] myTerrains = Object.FindObjectsOfType(typeof(Terrain));
 
 // through some algorithm (for loop?) find your specific terrain.
 // for my example, I just use the first one.
 Terrain myTerrain = myTerrains[0];
 
 TerrainData td = myTerrain.terrainData;
 // this might be of type float[][] or float[,] I'm not sure and don't feel like 
 // checking.  I'm sure you can figure it out right?
 float[][] heightmap = td.GetHeights(0,0,td.heightMapWidth,td.heightMapHeight);

There are also functions to set the heightmap. All the float values will be between 0 and 1, don't set a number outside of 0 and 1, it won't work. The TerrainData class is very difficult to work with, I found out, and pretty much undocumented. Unfortunately I had to go through a grueling process of learning how it worked. Let me know if you have more questions.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Can I set a non-power-of-2 sized heightmap to terrain? 1 Answer

Start another thread for a function 1 Answer

Generated terrain heightmap is flipped from the alphamap. 1 Answer

Height Map Issues 0 Answers

Gradual Terrain Smoothing from a Flat Area (at Runtime) 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