• 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 Ishkur · Mar 05, 2014 at 11:29 PM · terrainterraforming

Terrain's SetHeights method misbehaving

Hello, I am trying to raise terrain height in controlled, consistent increments of 1 Unity unit.

Every time I attempt to raise my terrain by 1 unit, however, SetHeights instead raises it by 1 unit and some fraction of a unit.

My terrain height is set to 500. I use GetHeights to retrieve the height value of a coordinate and store it in float[0,0] height.

To height I add 0.002f to the value, and then call SetHeights(coordinates, height).

Every time I call GetHeights, I log the float value retrieved, and every time I set the heights, I log the value of the float set.

alt text

It seems SetHeight is trying to set the proper float value, but upon getting the heightwe notice that some extra is put in there. What the log should be showing is increments of 0.002, 0.004, 0.006, etc...

Does anybody know why SetHeight is being inaccurate?

getsetheight.png (24.1 kB)
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
1
Best Answer

Answer by Eric5h5 · Mar 05, 2014 at 11:53 PM

Heights are actually 16-bit unsigned integers internally, where 1.0 = 65535. Therefore not all float values can be represented as heights, and they are rounded off to the nearest 1/65535.

Comment
Add comment · Show 2 · 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 Ishkur · Mar 06, 2014 at 12:09 AM 0
Share

Wait, why? Is that dumb? I'm not sure, but I feel like that's dumb.

Do you think that fact is going to cause problems if I need to incrementally raise and lower terrain over and over again?

The rounding will cause inaccuracies to pile up over time, right? I will eventually want to check if an area is flat, too, and other problems will arise due to the rounding, right?

avatar image Eric5h5 · Mar 06, 2014 at 12:17 AM 0
Share

It's not dumb to use ushorts for the height...that's what 16-bit raw heightmaps are. I'm not convinced that representing it as floats was the best decision, though, since that adds overhead of converting to/from ushort, and twice as much memory for the array. I guess it's "tidy" to represent heights as 0-1, but I think nobody would really have a problem with using 0-65535, considering the benefits of not needing float conversions and arrays.

I don't see that it would actually cause any problems, but you could do calculations as ushorts (or ints) and convert to float just to be sure.

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Gradual Terrain Smoothing from a Flat Area (at Runtime) 0 Answers

how to set Terrain SetHeights C# 1 Answer

Process heavy issues 0 Answers

How do I use Terrain SetHeights and GetHeights 3 Answers

How do I make a terraforming system? 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