- Home /
Destroy Terrain Trees And Their Colliders
ok so in my game I have a mechanic where you can chop down trees using a script attached to the player and one on a game manager object but the trees are painted into the terrain so they are hard to access. These scripts sort of work but the collider stays. so the tree mesh is gone but you can still collide with it. this is the method I use for destroying the trees
public void RemoveATrees(int index)
{
// remove a specific tree by index
List<TreeInstance> instancesTmp = new List<TreeInstance>();
int i = 0;
foreach (TreeInstance tree in terrain.terrainData.treeInstances)
{
// loop a all of a tree on terrain
if (i != index)
{
// basically add every tree to a Tmp array, Except a tree with a specfic index
instancesTmp.Add(tree);
}
i++;
}
// replace a tree instances in terrain data with a Tmp array
terrain.terrainData.treeInstances = instancesTmp.ToArray();
// refresh the terrain, get rid of collider of that tree.
float[,] heights = terrain.terrainData.GetHeights(0, 0, 0, 0);
terrain.terrainData.SetHeights(0, 0, heights);
}
}
but the collider still stays. So does any one know how to fix this?
Comment
Your answer
Follow this Question
Related Questions
Destroy Terrain trees and their colliders. 0 Answers
Not able to place trees 0 Answers
Destroy Terrain Trees And They Collider 0 Answers
How to simulate collisions on leaning trees? 1 Answer
how to add collider to trees made with terrain tool? 1 Answer