- Home /
OnCollisionStay is doing nothing.
I am trying to detect whether my player object is colliding with something that would hurt it using a tag to denote whether the object is "Dangerous" or not. My code looks like this:
private bool touchingDanger = false;
void OnCollisionStay (Collision col) {
if (col.gameObject.tag == "Dangerous") {
touchingDanger = true;
} else {
touchingDanger = false;
}
Debug.Log (touchingDanger);
}
And it does absolutely nothing. I have followed the Scripting API to a tee and I have restarted Unity multiple times to absolutely no avail.
Answer by tormentoarmagedoom · Oct 27, 2017 at 08:45 AM
Good day @Eoku_ !!
1- ( I only a suggestion) Replace at
void OnCollisionStay (Collision col)
for
void OnTriggerStay (Collider col)
2-
Check that at least one of the objects in every collision have a rigidbody component
Your first point is wrong. All OnCollision callbacks have a Collision parameter. All OnTrigger callbacks just have a Collider parameter.
omg! very true! i think it was a ontrigger XD, then maybe he needs to do a "OnTriggerStay"
The first one worked! Although the setup is not totally ideal for my game ( I want things like enemies and rigidbodies to be able to touch things marked as dangerous without falling straight through them ). I also expiramented a bit by replacing col.gameObject.tag with col.collider.gameObject.tag and col.collider.tag, but neither worked.
Your answer
![](https://koobas.hobune.stream/wayback/20220612141927im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to count collisions of the same tagged objects? 2 Answers
Distribute terrain in zones 3 Answers
Collision reaction not working 2 Answers
How do I use OnCollisionStay? 2 Answers