Search code examples
unity-game-engine2dphysicscollision

Unity 2D get the collision event without the physics


I'm using a collider 2D on a box and set it to trigger so my player can walk through it, when when i set it to trigger it doesn't fire the OnCollisionEnter2D anymore, is there a way to keep using the collision event without the physics engine taking in into consideration, if not then is there there another way to achieve this ? (i'm currently checking each frame in the update method and calculating the distance but this seems too heavy)


Solution

  • There is another function called OnTriggerEnter2D which may be what you are looking for. This should fire on collision, without causing physical interactions.

    You could have OnCollisionEnter2D and OnTriggerEnter2D both call a separate function to handle collisions, if this MonoBehaviour is added to both triggers and non-triggers.