I work on a shooting game where the character is in the forest. The forest I made with Unity’s terrain system. I’ve placed a few trees here and there (with the tree editor). Is there a way to make a tree fall when a missile (for example) hits the tree?
Can the trees within the terrain can interact with other game object?
Thank u in advance
If the trees are placed on the terrain object using the terrain system, they are static meshes and can’t fall. In order to actually create destructible objects they would need to be placed outside of the terrain system.
What you would need to do something like this would be:
- A tree mesh where the tree is whole, and a secondary mesh where the tree is destroyed.
- A collider, such as a simple capsule collider or maybe even a complex collider like a mesh collider.
- A script that uses the collision events to capture when a projectile hits a tree.
The script would probably do something like the following:
- Destroy the projectile object
- Swap the complete tree mesh with the destroyed mesh.
- Spawn an explosion particle system. (This will also cover up the mesh swap)
This is a very basic and low-tech implementation. There are countless other ways to implement it but this is the easiest one I can think of.
Hope that helps.
Destroyable terrain trees with example code:
It removes the terrain tree(s) based on explosion distance
and then spawns destroyed tree at its location.