- Home /
OnCollisionEnter with terrain not working
I am trying to make a sphere collide with a terrain. My sphere is having a sphere collider and a rigid body attached to it. For the sphere collider ,the 'is trigger' is unchecked and for the rigid body 'is kinematic' is unchecked while the 'gravity' is checked.
For the terrain, in the terrain collider the 'is trigger' checkbox is unchecked again.
My script attached to the sphere is as follows :
void OnCollisionEnter(Collision collision)
{
Debug.Log("Inside OnCollisionEnter ");
if(collision.gameObject.tag == "Terrain")
{
Debug.Log("Hit !!");
}
}
The sphere does drop down and collide with the terrain but this code isn't getting called at all !!
If it isn't getting called at all something must be wrong with your code elsewhere. However by default terrains don't have a "Terrain" tag...
Answer by hijinxbassist · Jul 01, 2012 at 06:57 AM
As @noob-e stated, the terrain does not start with a tag of "Terrain". This is most likely the problem. If the terrain does not have this tag:
Click Terrain in Hierarchy
Click Tag ("untagged") button at the top left of the Inspector
Select - Add Tag - at the bottom of the list
Expand the tags Array by clicking the triangle >
Add a new tag in an empty(now selected) area and name: Terrain
Click on the terrain again in the hierarchy
Select the newly created "Terrain" tag
Your answer
![](https://koobas.hobune.stream/wayback/20220613073515im_/https://answers.unity.com/themes/thub/images/avi.jpg)