Search Unity

newb: How to detect collision w/ the ground plane

Discussion in 'Physics' started by XEthanO, Jun 30, 2017.

  1. XEthanO


    Jun 29, 2017
    I'm working through the rolling ball tut and can't figure out how to detect a collision between the ball and whatever ground plane it's over (assuming I have several). The plane has a mesh collider on it, and the player has a rigidbody, and the script has OnTriggerEnter, but it is never getting called!

    OnCollisionEnter works, but OnTriggerEnter does not. What causes an OnTriggerEnter? Only another object with a RigidBody attached to it?

    Before you quote it, I've looked at the unity docs. "This message is sent to the trigger collider...etc". Yeah, I've seen it, it doesn't make sense. I'm missing something ridiculously simple, but I've never done this Unity thing before..
    Last edited: Jun 30, 2017
  2. Lyro_1


    Nov 27, 2016
    Hello man.

    OnTriggerEnter is, according to the documentation :
    This means that only colliders with "Is Trigger" checked are concerned by those properties, since they are considered as Trigger Colliders. So make sure first of all that your colliders are trigger colliders.

    Also, for your problem specifically, you could want to separe ground collision from any other object collision, for whatever reason. If you want to detect specificaly collisions with the ground, do the following :

    1. In your hierarchy, select all your planes, and go on the "Tag" tab, on top left of the Inspector
    2. Click "Add Tag..."
    3. Click on the little "+" in Tags, and add a new tag with the name you want (let's say you'll call it "Ground").
    4. Now select all your planes and add them as "Ground" in the "tag" tab.
    5. In your function, add a line to check if the collision was made with the ground :
    Code (CSharp):
    2. private void OnTriggerEnter(Collider other)
    3.     {
    4.         if (other.gameObject.transform.tag == "Ground")
    5.         {
    6.             //Do what you want when it collided with the ground
    7.         }
    8.         else
    9.         {
    10.             //Do something else
    11.         }
    12.     }
    13. /code]
    15. I can be very usefull to separe your scene's gameobject in tagged categories, to handle different behaviour depending of what they are.
    17. Hope it will help, tell me if not ^^
  3. tommapar


    Apr 16, 2021
    This is so weird... and 4 years late to the post. When I add a rigidbody, it immediately detects the collision. Without it, no matter how many triggers or box colliders I add, it doesn't work.
  4. MelvMay


    Unity Technologies

    May 24, 2013
    And you're surprised by that? With no Rigidbody(2D) you're asking implicitly for a Static collider. Static colliders are not expected to move and don't contact other Static/Kinematic colliders because why would they? That's what a Dynamic (Non-Kinematic) is for.
    sjoshua270 likes this.