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
1
Question by kvoepel3 · Mar 14, 2015 at 02:14 AM · colliderruntimeproceduraltreesterrain-trees

Unity 5 Terrain TreeInstance Scaling VS Colliders [Scripting]

When making a new TreeInstance to be added to a terrain in a script, modifying the scaling property seems to cause the colliders to behave improperly for some trees. Here is my quick and dirty runtime tree placing code (replicates very roughly what Mass Place Trees does):

 t.terrainData.treeInstances = new TreeInstance[0];
         for (float i = 0; i < terData.heightmapHeight; i++) {
             for(float j = 0; j < terData.heightmapWidth; j++)
             {
                 if(t.terrainData.GetSteepness(j / t.terrainData.alphamapWidth, i / t.terrainData.alphamapHeight) < 35.0f)
                 {
                     if(Random.Range(0, 100) < 15)
                     {
                         float perturbfactorx = Random.Range(0,2)*0.001f;
                         float perturbfactorz = Random.Range(0,2)*0.001f;
                         int prototypes = terData.treePrototypes.Length;
                         TreeInstance TI = new TreeInstance();
                         TI.position = new Vector3((j/terData.heightmapWidth) + perturbfactorx, 
                                                    (terData.GetHeight((int)j, (int)i) / 1000f) - 0.002f, 
                                                    (i/terData.heightmapHeight) + perturbfactorz);
                         TI.widthScale = 1;
                         TI.heightScale = 1f;
                         TI.color = Color.yellow;
                         TI.lightmapColor = Color.yellow;
                         TI.prototypeIndex = Random.Range(0, prototypes);
                         t.AddTreeInstance (TI);
                     }
                 }
             }
         }
         t.terrainData.RefreshPrototypes ();
         t.terrainData.SetHeights (0, 0, new float[0, 0]);

The variable "t" in this instance can be set to Terrain.activeTerrain if you're playing along at home. This code works perfectly (at least on my Perlin terrain that is 2000x, 1000y, 2000z), unless I change the following:

 TI.heightScale = 1f;

to

 TI.heightScale = 1.5f;

The trees still look fine, behave well with lighting, and get their colliders, but the colliders don't seem to scale, they are just centered on the now much taller trees. As a result, small objects can slide through the base of some of the trees without colliding. It's a pretty interesting effect, actually, but I'd like to know how to make these colliders scale with my trees, too.

Additional information, I am testing this using two standard Unity tree prefabs: Broadleaf_Desktop and Conifer_Desktop. My target is Windows PC.

All help is appreciated. Thanks!

Comment
Add comment · Show 2
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 getyour411 · Sep 05, 2015 at 02:04 AM 0
Share

Interesting question. Looking through Intellisense, I don't see collider interfaces. An alternative is to use the terrain treedata positions, shift to world space and create the capsule colliders manually. To avoid the double penalty of treePrefab collider (but not scaled, too small to help) + the manually created collider, might be worth removing the prefab collider.

avatar image getyour411 · Sep 05, 2015 at 02:08 AM 0
Share

...and I just found this post

http://answers.unity3d.com/questions/713772/mass-place-trees-scale-issue.html

which is puzzling because it's modifying heightScale as you did. If you added terrain.Flush(), I wonder if yours would have worked.

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

2 People are following this question.

avatar image avatar image

Related Questions

Tree colliders in Gaia (procedural worlds) 0 Answers

How to make trees in a terrain transparent in runtime? 0 Answers

How to make trees impassable? 1 Answer

how to add collider to trees made with terrain tool? 1 Answer

How to put colliders on trees 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