Pathfind around trees

I have set up some terrain with Unity’s build in system, including a bunch of trees with collisions. The collisions themselves work, but the pathfinding doesn’t recognize them as solid. I believe this is due to them being part of the terrain, and hence on the ground layer and not the obstacles layer. Is there some workaround for this?

I watched a video recently of a guy who placed primitive cylinders around the base of his trees. The cylinder penetrated the ground mesh. Then he made the cylinder a non walkable object & then simply turned rendering off on the cylinder.

I guess that would work, but I have a lot of trees, and I’m replacing them frequently.

This is on my todo list since about half a month. Currently the only solution is to place cylinders (or cubes if you want faster scanning times) around the trees. You can relatively easily write a script which does that for you though.

Glad to hear you have plans for it. I tried writing a script to automate it, but I have some error in how I’m calculating the tree positions, so the collision capsules end up a few feet offset from the actual location. Its based on the distance from the origin, so I think its an error in the scaling.

Hi,

Any news on this field? I have a tree prefab with “Tree” layer and terrain with “Terrain” layer. Astar is set to use “Terrain” and ignore “Tree”.

When i’m placing tree manually, that’s fine. But if to use Unity’s brush for build-in trees, astar cant see them.

I dont know what is a reason for that: in my game, i’m sending a ray to interact with trees, and ray “sees” both prefab trees and terrain trees.

Okay, what i did is modified your DynamicGridObstacle script, made it StaticGridObstacle (just removed Coroutining and run UpdateGraphs only once), attached it to tree prefab and painted terrain with that tree.

However, during the running, i’m getting an error and trees are ignored
64 small areas were detected (fewer than 10 nodes),these might have the same IDs as other areas, but it shouldn’t affect pathfinding in any significant way (you might get All Nodes Searched as a reason for path failure).

As far as i understood, there are areas between trees (i have 30 trees).
How can i force them to have the same id?

Edit: actually, i had decreased size to 1, but bot is still ignoring the trees.
Edit 2: looking like i have the same errors even on clean scene (i’m playing with Example2).