- Home /
Enable tree colliders near you, far ones are disabled
Okay, so I thought of a brilliant idea that I'm not sure how to even start yet. I have a heavy forest in my game, and by check-marking the "Create tree colliders" in the terrain collider, my game drops from 80 to 20 FPS, and I have a pretty good computer too.
So, my idea is that there will be some kind of way where I can modify this tree colliding stuff by having where only the trees around the main camera (the controller, in this case) will have their tree colliders enabled, and the rest that are farther from the given radius will have their colliders disabled. Basically, this is almost like that billboard tree thing where the trees will be rendered 3D within the given radius.
I'm not really advanced at this kind of stuff, so how should I get started by doing this? Is it possible to make a script of this somehow or do I have to make some plugin addon API thingamajiggy joopdeebop?
$$anonymous$$aybe a coroutine that checks square distance of all the trees? Although since I believe this is what a collider does anyway, I'm not sure if it will speed thing up. However, as a coroutine, you could yield after processing the first 10% of the trees (for example) so that the complete update will finish every 10 frames.
The question is what will you do about the AI?
On a side note, what kind of colliders are you making for the trees?
Little confused here. You mean that I will create something that will check for 10% of the trees around me every 10 frames? I'm not sure what you mean by the AI, either. And the kind of colliders I'm using are just simple little capsule colliders that just cover almost the complete radius of the tree trunk.
10% in one frame, yield, 10% in next frame, etc -> 100% in 10 frames (example)
Doing all of them in every frame will probably be more work than you need to do.
The AI problem is that enemies won't know where the trees are for pathfinding, so they may just walk right through them.
Here is a method that moves the colliders to the nearest trees : http://answers.unity3d.com/questions/282910/tree-collision.html#answer-406989