• 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

· Add your 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?

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

2 People are following this question.

avatar image avatar image

Related Questions

Terrain grass does not show up on runtime 1 Answer

Is there a way to hide terrain grass using a shader like a depth mask. 0 Answers

meadows and fields 0 Answers

Alpha channeled grass 0 Answers

Mass Place Trees on slopes 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