- Home /
Why is OnCollisionStay activating before collisions?
So the rigidbodies collide at the right place, but the collisions seem to be detected before time. I need to get the contact points, but they are way above were they are supposed to. This also happens with the x axis, and I don´t think it´s code related, but here it is just in case:
void OnCollisionStay(Collision coll)
{
//minValue is 0.6f
for (int a = 0; a < coll.contacts.Length; a++)
{
if (coll.contacts[a].normal.y < -(minValue))
{
Debug.Log("normal above: " + coll.contacts[a].normal + "location: " + coll.contacts[a].point);
aboveColl = coll.contacts[a].point.y;
}
}
}
the code isn't helping any. what does the collider arrangement look like the moment they're colliding?
Answer by Feref2 · Nov 04, 2018 at 09:11 PM
Well, actually everything works fine. I don´t know why, but looks like OnCollisionStay is called before collisions. Use OnTrigger versions if you want it to be accurate. If you need OnCollision, then compensate that extra space using raycast.
Answer by redmanwielder · Nov 02, 2018 at 03:20 AM
It seem you are missing some item on Inspector. Add "Box Collider" and set the "Trigger" check on "Object", "Edit Collider" to fix contact area .
Thanks, but changing the collider´s shape causes other issues, like wrong physics. Besides that, I don´t know why that object doesn´t have a collider on it, but this problem happens even when it has it. Also, for some reason the gravity is pulling the object below more than is supposed to.