Colliding with trigger with rigid body generates multiple OnTriggerEnter() calls

Hi!

I have the following situation: there is a Player object with a CapsuleCollider and a CharacterMotor script, and an Item object with a CapsuleCollider set to trigger and a custom script to detect collisions with the Player object:

void OnCollisionEnter(Collider collider) {
    if (collider.gameObject.tag == "Player") { HandleCollisionWithPlayer(); }
}

The problem with this is that if the Player is not moving and the Item appears at the position of the Player, they will not collide until the Player moves.

To solve this I added a rigid body to the Item, and it works, except that now OnCollisionEnter() is called multiple times (probably twice, haven’t counted).

The questions are:

  1. why does colliding with a trigger and rigid body generate multiple OnCollisionEnter() calls?
  2. is there a better way to detect collision between a non-moving object and a trigger than adding a rigid body?
  3. if none of the above can be avoided, is there a better way to disable the collision detection than setting a flag in the script? E.g. disabling the whole script, setting an already defined flag, etc.

Thanks for the help in advance!

Is the object animated? If yes, then most probably it’s moving so fast that it moves forward, just enough to touch it again.

I had something similar with a spring that was animated but was pushing the player with AddForce via script. So when the spring was playing it’s animation, by the time the player left the spring, the spring itself touched him again. So i just added a timer and checked against that as well if it should add force again or not. Just to give a cooldown effect.