I am trying to make a simple test 2D platformer game. My character has gravity and falls to the ground, and when he hits the ground he stops (which I would expect to be a collision).
Here’s what I have to assure this collision happens:
- I have this method in my player controller script:
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isGrounded = true;
Debug.Log("In OnCollisionEnter2D");
Debug.Log("isGrounded is now " + isGrounded.ToString());
}
}
-
The character has a 2D box collider and a 2D rigidbody. The rigidbody is Dynamic, not Kinematic.
-
The “ground” is a tilemap with a Tile Map 2D collider (it does not have a rigidbody).
-
Both colliders are NOT triggers.
-
The character can jump, so the collisions should be happening everytime he falls back down.
-
Just in case I’m using the wrong method, I also have the two methods:
OnTriggerEnter2D(Collider2D collider)
OnControllerColliderHit(ControllerColliderHit hit)
I gave them the same debug statements. Neither of them detect a collision.
The OnCollisionEnter2D (and the other likewise methods) have 0 references and are “unused” according to Visual Studio. I don’t know if that’s a problem.
With all this, I expect the Debug.Log() statements to show in the console, but they never do. I would appreciate some expert help as to why the collisions aren’t happening. If you need more insight into my project, I will gladly give it. Thanks for the help!