- Home /
ignoreing enemy collisions when hit, and turning the coliders back on
I'm trying to create a system when my player gets hit the player ignores all enemy collisions for a brief moment so the player could have a chance to escape. Then when the time period is over he can get hit again. The problem is that when the player gets hit by the enemy, the same enemy that hit him can never touch him again other enemies can, but once they do the can never touch him again either. I have been trying my best to fix this please help me; heres the code.
if (ghostmode && coll.gameObject.tag == "charger" ) {
Physics2D.IgnoreCollision (gameObject.GetComponent<Collider2D> (),coll.collider);
}
if(ghostmode = false){
Physics2D.IgnoreCollision (gameObject.GetComponent<Collider2D> (), coll.collider,false);
}
Answer by Apfelbox · Aug 22, 2015 at 11:17 PM
I would recommend you to look at Coroutines.
Just set a bool variable (bool isVulnarable) false if the player gets hit and start a coroutine to wait a few seconds before you set it true again.
im sorry but the coroutine dose not really fit right in the script do you have another option.
Your answer
Follow this Question
Related Questions
Move player position a bit 2 Answers
Problem with colliders in topdown 2d scene with many floors 1 Answer
Enemy wont damage player 0 Answers
Player Collider isn't found by Physics2D 2 Answers
Enemy wont damage player 2 Answers