I am making a game to check if a object touched the ground. But my code doesn’t work. I have tried everything. The object has a Rigidbody, and the collider is set to “isTrigger”. What am i doing wrong?
Here is the code:
public void OnTriggerEnter(Collider other)
{
if(other.tag == "Ground")
FallenOver = true;
}
See the chart on this page where it says “Collision Generates trigger messages” to see all of the conditions for when the message occurs
Also, remember that OnTriggerEnter doesn’t work for 2d colliders. You’d need to use OnTriggerEnter2d if you are using 2D physics.
1 Like
I did this too, it still doesn’t work…
I have an Dynamic Trigger Collider, it should fit with everything…
jeeriel10:
, it still doesn’t work…
We know these methods work.
Try a blank scene, two objects, set it up, a test script, we KNOW it will work.
You should be printing the tag of other
… maybe it isn’t what you think!
Sounds like you wrote a bug… and that means… time to start debugging!
By debugging you can find out exactly what your program is doing so you can fix it.
Use the above techniques to get the information you need in order to reason about what the problem is.
You can also use Debug.Log(...);
statements to find out if any of your code is even running. Don’t assume it is.
Once you understand what the problem is, you may begin to reason about a solution to the problem.
(1) Maybe you assigned some diffrent layers to them, and this layers cant interact with each other. Check out are they on default.
(2) Just to be sure. Understand that you not working in 2D, right? Because then should use:
MonoBehaviour .OnTriggerEnter2D(Collider2D)
I have the ground on Ground, and the falling object on deafult.
And i am working in 3D!
Did you check out Layer Collision Matrix between Ground and Default?
Didi you try putting both on default?
I did it now, Deafult couldent collide with Ground, so i chanced the falling object to water, which can collide with ground. This didn’t work too…
Putting them both on deafult wouldn’t work, becouse the script checkes for layer ground…
I tried debugging. The scripts knows that it collided with something. But after the if statement, it does nothing.
Bro where in your code script checs for ground layer… you checking for gameTag… not layer
putt both objects on default layer, and assign gameTag “Ground” to ground gameObject
1 Like
I see! This was the problem. I set the ayer to ground, not the tag…
1 Like