Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by LiTux · May 08, 2013 at 08:50 AM · terrainsizeterraindataslope

terrainData.GetSteepness() usage

How is GetSteepness() used? I just noticed, it accepts an x and y, not an x and z. This is confusing me. What z is used if x and y are given.

Also, I've normalized the coordinates based on terrainData.size. For some reason, it returns 1 as the steepness every time, even on sloped hills.

Comment
Add comment · Show 1
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 Ebil · May 19, 2013 at 11:04 PM 0
Share

No help for you, but I also got a similar Problem, I always get 0 as result...

//Edit: Never$$anonymous$$d... forgot to normalize it...

I dont know what you mean by you used terrainData.size, but I normalized the Vector3 of a Raycast that I had from the terrain, since I dont know how your game works I cant tell you if it would be also a solution for you.

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Eric5h5 · May 20, 2013 at 12:15 AM

A terrain uses 2D data (namely, a heightmap); there is no Z used in the creation of a terrain. It's not relevant. Perhaps it would make more sense to specify X and Z, but in this case X and Y refer to the width and length.

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

Answer by ArtOfWarfare · Dec 13, 2015 at 03:55 AM

When using GetSteepness(), you should provide your X and Z values in place of X and Y, and you should normalize them so that they're between 0 and 1. If your X and Z values have the same origin as the terrain but need to be normalized, you can use the following:

 float normalizedX = myX / terrainData.size.x;
 float normalizedY = myZ / terrainData.size.Z;

Now this part isn't documented anywhere, so this is why I really feel compelled to answer this question: GetSteepness() returns a float between 0.0 and 90.0 representing the Euler angle of the slope. This seemed like a bizarre choice to me - I had expected it to be a float between 0.0 and 1.0.

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 Bunny83 · Dec 13, 2015 at 01:41 PM 0
Share

A value between 0 and 1 would actually be bizarre. What would it represent? Still an angle? If it's an angle you would use some kind of angle unit. So either degree (what they did) or radians. If you don't want to get back an angle but the actual slope, the returned value would represent the tangent of the angle and therefore would be in range 0.0 to +inf. A value of 1.0 would be 45°, a value of 2 would be 63.435° and "+inf" would be 90°.

You never represent an actual angle as a value between 0 and 1. That wouldn't make much sense.

ps: It's actually an ordinary angle and has no relation to Euler angles. Eulerangles describe an orientation within some kind of Euclidean space

avatar image SSStreetFighter · Apr 27, 2021 at 09:03 AM 0
Share

That is interesting but it does not explain his main question: Why is the slope remaining constant? If is is always the same number that means GetSteepness() is not working. Mine returns a value of 0 constantly. Even when my character walks uphill.

avatar image Bunny83 SSStreetFighter · Apr 27, 2021 at 05:50 PM 0
Share

I can't replicate that that issue. Just thrown in a terrain, painted some hills on it and when I walk across the terrain I sample my player position. I get, as expected, the angle between the surface normal and the world up vector. Maybe you have the wrong coordinates? Have you checked you used the right coordinates? It's actually more than just dividing by the terrain size. The coordinates need to be relative to the terrain object. Of course this is not necessary if the terrain is at position (0,0,0). However you should always think about the general case.

This works perfectly for me:

     Vector3 v = transform.position - terrain.transform.position;
     v.x /= terrain.terrainData.size.x;
     v.z /= terrain.terrainData.size.z;
     var sample = terrain.terrainData.GetSteepness(v.x,v.z);

If you have multiple terrains in your world, you can additionally raycast downwards to get the objects under your feets. If it's a TerrainCollider, you can use the above code to get the angle at this point using the data from the collider you've hit.


Note that a Terrain can not be rotated or scaled with the Transform. So be careful when using InverseTransformPoint. This method does take scale and rotation into account which is not what you want since the Terrain seems to ignore those. Only the position is relevant.


So if you have issues I recommend you check the coordinates you pass into the GetSteepness function. As mentioned in the docs and above, they need to be in the range of 0 to 1.

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

17 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

Related Questions

Terrain heightmap isn't smooth 0 Answers

How do I increase the map size? 1 Answer

Is there a way to create multiple terrains that use the same settings? (eg textures, grass wind settings) 0 Answers

Why does my tree script not work 2 Answers

How to generate a complete terrain via Script 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