Interaction with Trees?

I keep seeing all of these games where people can interact with the trees placed on the terrain, however… I can’t wrap my mind around it. I’m trying to make a script to where a unit will go up to a tree and “Cut it down”, however I can’t for the life of my figure it out.

I also need to find a way to select the “Nearest tree”… Hmm…

I don’t think there’s any one right way to do it. If you want to cut a tree down, you could replace the tree mesh with a stump and the top(as a rigid body).

I created a prefab for the tree and placed them manually for the time being. I’m trying to figure out if they used the trees from the terrain painter.

It’s kind of complicated and annoying. You need to find the point on the terrain that you hit, and then loop through every tree, compute its worldspace position, and see if it’s close enough to the point you hit. Then you create a copy of the tree array with that one particular tree now deleted or replaced by a stump and assign it back to the terrain. If it had a collider on it you also need to do an additional refresh to get the collider to disappear. Here’s an example:

http://forum.unity3d.com/threads/110354-Finally-Removing-trees-AND-the-colliders