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 ChristmasEve · Apr 15, 2015 at 09:33 PM · terrainmapheightmapheightmmo

Formula for Terrain sampleHeight

I'm really struggling to find out how Unity interpolates between individual heights within my 2049x2049 height matrix. If, for example, you want to get the height of the terrain and the position you're looking for is halfway between 10,10 and 11,11 in the height map, I would assume that the height should be: find (height(10,10)+height(10,11))/2 and find (height(11,10)+height(11,11))/2, then add those two results together and divide by 2 (I'm saying 50% of the way between just to simplify my question). What happens is, if I'm on a flat part of the terrain, the result is right on. If I'm on a slight incline, the result is very close. If I'm on a steep gradient, the result can be as much as a couple meters off. What is going on? How does Terrain.activeTerrain.sampleHeight() calculate it?? Please keep in mind that in my explanation above, I'm not using world coordinates and I know sampleHeight uses world coords. I do that conversion from world width/height to 2049x2049 and I know that isn't the problem.

The reason I need to know this is, the scale of my MMO is becoming too large for Unity to handle the server side so, I want my C# code to run on it's own, without the Unity Engine. So, I'll have to calculate (on my own) the exact height on the terrain to place players and monsters. If I can figure this out, I'll be most of the way there. The only other thing holding me back from separating my server from Unity is that I depend on Unity's NavMesh for pathfinding right now.

Comment
Add comment · Show 8
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 AlwaysSunny · Apr 15, 2015 at 09:33 PM 0
Share

I remember needing this too. See if this is helpful: http://answers.unity3d.com/questions/469151/reproducing-terrainsampleheight-for-custom-mesh-te.html

Your situation is different, but I'm pretty fuzzy on this kind of operation; been a while... it's gotta be something about how high a height value of 1 is on the terrain in world space; using that is the key for the space conversion.

avatar image AlwaysSunny · Apr 15, 2015 at 09:40 PM 0
Share

You're not scaling the terrain axes separately, are you? Because this is exactly what would happen if you were.

avatar image ChristmasEve · Apr 15, 2015 at 11:02 PM 0
Share

I read that post. Thanks Sunny. I think I did come across that thread a while back but I wasn't sure if this was the same case. But, I just read it again and I guess my problem is that I am not interpreting anything as a triangle or quad. I'm only doing a weighted interpolation between the four points I'm standing within. I guess this is my problem. Below is output from my game. In this case, my height is only off by 0.8f, which is still significant though. The 3x3 matrix of values above that are all the heights in a 3x3 area around me, with the center value being the X,Y you would get by dropping the decimal portion of my calculated position on the height map. I guess I don't understand interpolating on quads or tris enough. I can't seem to figure out HOW one can get 212.8821 from this height map data :(

207.7825, 207.3613, 207.929

214.9057, 212.7815, 214.7226

221.443, 218.1469, 218.3666

sampleheight = 212.8821 my height = 212.0078

As far as scaling goes, I did check just now and my terrain is set to (1,1,1).

avatar image AlwaysSunny · Apr 15, 2015 at 11:11 PM 0
Share

In the end, the terrain is a bunch of triangles; treating it like quads might indeed account for the behavior you're observing. You could perhaps visually inspect the terrain to see the orientation of the hypotenuse of each quad's pair of tris. You could probably discover the winding order experimentally and build off the info I discussed in that linked question.

If this operation is only necessary a handfull of times per frame, you could always raycast down at the terrain collider for the point. As a bonus, you'd get the normal without additional effort.

avatar image ChristmasEve · Apr 15, 2015 at 11:13 PM 0
Share

I suppose it would help if I mentioned the fraction part too so you know what values I'm interpolating on: X is 0.4578247 of the way to the next value on the height map and Y is 0.5102539 of the way to the next value. I'm not asking you to do calculations for me and figure it out but I'm mentioned this data just in case you're curious. I guess if you or anyone knows the general formula I can use based on my world location (or heightmap location), I can try it and see if it works. I greatly appreciate any help you can give :)

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

Problem with heightmap and terrain height maxing out at 10000, proportions *Solved* 0 Answers

Best way to get terrain positions from a given height range 2 Answers

Trying to tile terrain, encountering strange axis flipping 0 Answers

Terrain resolution for a MMO 4 Answers

Having some serious issues making height maps work. 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