- Home /
OnCollisionStay is not returning anything
I have a physics-controlled ball using a rigidbody, and I wish to use the normal of its contact point with the level. I intend the end result to be that when a forward force is applied to the ball, the y direction of the force is brought parallel to the surface that the ball is travelling on.
Most sources would suggest that OnCollisionStay is the way to go, but whatever I do, I can't get it to return any collisions whatsoever. The code I'm using follows Unity's example from the script reference - I can't do anything more with it until it actually works!
void OnCollisionStay(Collision collisionInfo)
{
Debug.Log("I am colliding");
foreach (ContactPoint contact in collisionInfo.contacts)
{
Debug.Log(contact.thisCollider.name + "hit" + contact.otherCollider.name);
Debug.DrawRay(contact.point, contact.normal * 100, Color.white);
}
}
Naturally, neither the Debug.Logs or the DrawRay are getting called at this stage.
I've tried messing around with the ball's rigidbody collision detection and putting a kinematic rigidbody on the level, but nothing seems to make a difference.
what are the two objects colliding? Because for example, two rigid-bodies colliding will not return any collision as occurring unless colliders are also attached.
one is a floor object which has a mesh collider, the other is the controllable ball which has a sphere collider and a rigidbody.
I suggest first doing something with OnCollisionEnter() just to test that the collision is being read initially
Tried that, same result. It's not falling through the floor or anything, so it's definitely colliding... it just doesn't seem to want to admit it!
So I made a new project to test it independently of my project, and it worked. Reopened my project, and now it works. I really REALLY hate it when Unity does that...
Answer by Rob 6 · Jul 12, 2011 at 07:57 PM
It's not much of an answer, but all it took was a restart of Unity. Similar things have happened before, I just didn't remember! Tip of the day: If bulletproof code doesn't work, restart Unity and it will.
I have had the collision system do this to me on multiple occasions, and restarting has almost always helped.
yeah, I guess it's just one of those things! It probably means PhysX has gone a bit haywire and needs a reset. Who knows?