• 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
Question by theness_ · Jun 11, 2015 at 12:51 AM · terraingrassslope

generate grass on terrain only when there's no slope

Hello,

I try to generate terrain grass using script based on weather there's a slope or not (slope = no grass, flat surface = grass). I thought it should be simple but for some reason my code doesn't work. I tried two things, first I tried this:

         int[,] grass = new int[resolution+1, resolution+1]; 
         for (int x = 0; x <= resolution; ++x) {
             for (int y = 0; y <= resolution; ++y) {
                 
                 float steepness = terrain_data.GetInterpolatedNormal((float)x / (float)resolution, (float)y / (float)resolution).y;
 
                 if (steepness > 0.9f)
                     grass[x,y] = Random.Range(0, 2);
                 else
                     grass[x,y] = 0;
             }
         }

but for some reason I'm getting some heavy slopes with grass on them. then I tried using Abs(GetSteepness()), but again, there are some surfaces that should have grass and remain empty and some clear slopes that should be empty but end up with grass on them.

what am I doing wrong?

thanks!

added illustration pic: alt text

grass-problem.jpg (242.4 kB)
Comment

People who like this

0 Show 0
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

  • Sort: 
avatar image

Answer by getyour411 · Sep 22, 2015 at 03:08 AM

GetInterpolatedNormal returns Vector3, so I'm a little surprised 5 doesn't generate an error? If that's the issue, then it would be if (steepness.y > ....) on line 8

Comment

People who like this

0 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 theness_ · Sep 24, 2015 at 10:36 AM 0
Share

read carefully, the line ends with ".y"

 terrain_data.GetInterpolatedNormal((float)x / (float)resolution, (float)y / (float)resolution).y;

thanks though :)

avatar image getyour411 theness_ · Sep 26, 2015 at 06:52 AM 0
Share

I have some similar code and have found the normal.y needs to be severely restricted; try .98 or a higher value and see if the results change.

avatar image getyour411 theness_ · Sep 26, 2015 at 07:34 AM 0
Share

Oops, just looked at my code and it's the other way around. I have

 if(normal.y < .7f)
 // apply steep painting rules
 )

What does grass = 0 mean in your code? Use the 1st detailPrototype?

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Terrain textures are way too dark 0 Answers

shake grass randomly method 0 Answers

Grass detail mesh is stretched for no reason... 2 Answers

Unity HDRP Terrain Trees not working ! Version 2019.2.8f1,Unity HDRP Terrain Trees not working Version 2019.2.8f1 0 Answers

"Trouble with "Grass Detail Distance" setting in Unity - How to increase distance beyond 40?" 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