- Home /
How can I have mass amount of tress without performance loss?
Hello everyone, I'm currently working a project where I would like to place a mass amount of trees with colliders and use my raycast to detect whether or not the player is looking at the tree or not. I done some research on this and found i would have to write a script that adds colliders to each tree during run time but only in Java not C#. Does this effect performance or do you guys know of a different way this can be accomplished without taking a massive hit in performance? Any info would help. thanks in advance. Oh and one thing I know about the prefab method but unity likes to turn all colliders from the tree to one terrain coliider which then returns back that the player is looking at the ground not the tree.
A single raycast forward isn't all that expensive. What concerns about performance do you have?
Answer by Bloodyem · Jun 29, 2014 at 04:00 PM
Hmmm...raycasting by itself can get pretty pricey as far as performance. Do you need them to be in any particular order? You could possibly create a work around where you use static particles to place the trees...I'm not sure, I'll look it up and edit, but it seems like that might be a decent bet.
EDIT Yes, you can add colliders to particles. This ought to at least make placing them quick and easy, but it still may affect performance, depending on the poly count.
GameObject->Create Other->Particle System
Component->Particles->World Particle Collider
Then set the particles to be meshes and load up your tree mesh into it.
Answer by getyour411 · Jun 30, 2014 at 06:17 AM
Regarding this
"Oh and one thing I know about the prefab method but unity likes to turn all colliders from the tree to one terrain coliider which then returns back that the player is looking at the ground not the tree. "
the workaround for that is to compare the raycast hit .y vs the terrain SampleHeights at the same location; if the .y is a bit higher, the raycast/player is looking at a tree, not the terrain.
http://answers.unity3d.com/questions/650308/how-do-i-interact-with-terrain-trees.html
Your answer
Follow this Question
Related Questions
Removing colliders from terrain trees 2 Answers
Scripts on Terrain Trees 2 Answers
How to disableTerrain Collider but keep the Tree Colliders? 1 Answer
Disable collider on only 1 tree type not all? 1 Answer
Terrain tree colliders as triggers 2 Answers