- Home /
Detect Collision Again ( trigger OnCollisionEnter again )
Hello! I'm nearly finishing my game, but there's still something i want to know how to do best.
My character detects the collision with enemies using OnCollisionEnter, and then I call a function that will make the hit animation and etc.
The problem is, if I stay inside the enemy collider, it wont detect the Collision Again, because its still colliding, it havent "entered" again since the first time, I can understand this. One may say that i should use OnCollisionStay with some boolean tweaks, so it can detect the collision every time. The problem is, that using OnCollisionStay may affect the performance...
I simply want to force OnCollisionEnter again, is there a way to achieve this? Maybe if I could remove my characters from every collision someway, and then, after sometime, detect the collisions again.. is there a way? Thanks!
Answer by SepM · Jul 07, 2014 at 02:06 PM
It's just theory, but possibly, you can set a boolean variable on OnCollisionExit() that becomes false. On OnCollision(), you can check if the variable is false. If it is, then activate, your OnCollisionEnter() code, setting the variable to true until it exits once again. I'm not sure if this method will work, but maybe with a little tweaking, it may work out.
I hope this helps you finish things up.
Your answer
Follow this Question
Related Questions
OnCollisionEnter is slow... 2 Answers
Rigidbody not working 0 Answers
How to move a tank? 1 Answer
Child calling parent's OnTriggerEnter when no Rigidbody is attached to child 1 Answer
collision without rigidbody 1 Answer