- Home /
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?
Answer by rutter · Mar 13, 2012 at 11:51 PM
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.
I didn't realise that you could switch between layers dynamically! Do you know if there are any performance issues related to switching between layers at runtime? Cheers
Not sure! It seems reasonable to assume there might be some physics complications, but they're probably fine if you're not doing this especially often.
Answer by nasapc123 · Mar 13, 2012 at 11:50 PM
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
}
Your answer
Follow this Question
Related Questions
changing gravity OnTriggerEnter 1 Answer
Trigger Spawning? 1 Answer
Can't click gameobject when over another trigger? 1 Answer