Temporarily ignore collisions between player and enemies

When my player collides with an enemy I would like to allow the player to walk through the enemy (with flashing animation to indicate damage).

I thought that this would be best achieved by setting the collider of the enemy to a trigger. But… this is no good because OnTriggerEnter doesn’t appear to provide the contact points upon collision (which are essential).

What are my choices?

If you can get away with it, temporarily disabling one collider by setting Collider.enabled to false would be simple.

Otherwise, you might try setting up collision layers and tweaking GameObject.layer on the player and/or enemy. You could temporarily put one character on a layer which doesn’t collide with other characters.

possibly you could use

Physics.IgnoreCollision(other.collider, collider);

this would ignore collisions, and then possibly check th distance betwen you and the enemy, or wether the object is inside the trigger using

OnTriggerStay(){
//apply damage
}