1
Vote

NaNs from colliding objects with zero relative velocity

description

In Collision.cs, the collision calculations in the constructor do not take into account a zero-length Vector3 for collisionNormal, collisionTangent, etc. When Normalize is called on these Vector3 values, the result is NaN for all Vector3 components (since you can't normalize a zero-length Vector3... it has no direction). This ends up corrupting other values in Thing, making the object disappear.
 
Vector3 values need to be verified to have a length before being normalized, and if they don't, substitute values need to be added. This only appears to happen when two objects are exactly touching (or overlapping) but have no velocity towards each other... relativeVelocity ends up being zero.

comments

tkubaska wrote Apr 18, 2007 at 8:03 AM

How can CollisionNormal be zero? Wouldn't this mean that two balls were occupying the same space?

But for relative velocity, right now I can't think of anything beyond a conditional before the Normalize(), which is probably not the most performance optimal solution.

jasonmauer wrote Apr 18, 2007 at 7:37 PM

It happens when objects are inserted into the world. There isn't any checking to see if something is already occupying the same space, so you can end up with objects that are touching (or overlapping) but are not actually moving towards each other. The collision response calculations assume a real collision with movement.

wrote Feb 1, 2013 at 1:51 AM