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…
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 :
In your hierarchy, select all your planes, and go on the “Tag” tab, on top left of the Inspector
Click “Add Tag…”
Click on the little “+” in Tags, and add a new tag with the name you want (let’s say you’ll call it “Ground”).
Now select all your planes and add them as “Ground” in the “tag” tab.
In your function, add a line to check if the collision was made with the ground :
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.transform.tag == "Ground")
{
//Do what you want when it collided with the ground
}
else
{
//Do something else
}
}
/code]
I can be very usefull to separe your scene's gameobject in tagged categories, to handle different behaviour depending of what they are.
Hope it will help, tell me if not ^^
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.
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.