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:
- why does colliding with a trigger and rigid body generate multiple OnCollisionEnter() calls?
- is there a better way to detect collision between a non-moving object and a trigger than adding a rigid body?
- 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!