Collision2D not detecting when playing is jumping

Hello,

I am designing a game in such a way that when a player collides with a coin, it gets destroyed. And quite frankly, that is working. However, whenever my player is jumping, the coins are acting as RigidBody objects (even though I don’t have RigidBody attached to it), not letting the user pass through them, and not detecting collision at all.
Here are some more information:

  • Player has a RigidBody
  • Coin do not have a RigidBody
  • Coin has IsTrigger checked
  • Yes, everything is 2D
  • I am using a Polygon2D collider for the Player and the coins) (I also tried it with a box collider. Doesn’t work)
  • I have tried adding a RigidBody2D to my coins after doing some research. Doesn’t help.

Any ideas? I will be REALLY thankful!

private void OnTriggerEnter2D(Collider2D collision)
{
    Debug.Log("Collider with" + collision.tag);
    if (collision.tag == "Player")
    {
        SoundManager.Instance.playSound(SoundManager.Instance.coinHit);
        DestroyObject(gameObject);
    }
}

So you do collect the coin when walking, but collide with it and don’t collect when jumping? If that’s the case, then the script you provided has nothing to do with it. Your jump script is more likely to be the issue, for whatever reason.

@Ramlock You are right. Actually, when jumping I had a horizontal raycast which scans for colliders and prevents my player to move that direction if they find any. Even though isTrigger is on, the RayCast still detects the coin colliders and so won’t let my player pass. Fixed this by telling my RayCast to ignore any objects (or colliders) of type Coin