- Home /
Trees collide but says collided with terrain
So I added some trees to my terrain using the mass tree tool. I had already created a prefab for my tree and added a capsule collider to it.
So I edited the settings of the trees for the terrain and set it to use that prefab.
Note that the prefab has the tag Tree and the terrain has the tag Ground.
However when the player collides a tree, the log says it collided with the terrain, not with tree (I print the tag of the collider's gameobject). I don't want this behaviour because I do things depending on where the player hit. Is it possible to fix this?
Answer by GwenoleGerard · Oct 07, 2013 at 09:45 AM
,Do you use different Layer for your trees and your terrain ? If you don't you can try this:
In Edit->project settings->Tag you can add Layer, create one for the tree and one for the ground for example.
Then in your tree prefab change the Layer (top right in the inspector) for the Layer you create for the tree. Do the same with your terrain with the appropriate layer.
Then in Edit->project settings-> physics you can choose which layer collide with tree Layer and Terrain Layer.
You can also add a script with the method OnCollisionEnter(Collision collision) and in this method add the condition if(collision.tag == tagYouWant) or if(collision.tag != tagYouDontWant).
The OP is referring to the trees as part of the terrain system, not as separate gameObjects. Therefore there is no way to distinguish a tree collider from a terrain collider; layers, tags, nothing.
See various other posts regarding the terrain and treePrototypes data :
Answer by minas1 · Oct 07, 2013 at 01:17 PM
I found the answer. I move the player using translate (not velocities), so it is not detected. I'll have to change it.
Your answer
Follow this Question
Related Questions
Disabling colliders in Terrain Trees? 1 Answer
Tree Colliders not working 1 Answer
Colliding with trees using mesh colliders 1 Answer
CreateTerrainGameObject not creating tree colliders? 1 Answer
Destroy Terrain Trees And They Collider 0 Answers