Collision Callbacks
Ian Mallett 04 Dec 2010 00:41
Hi,
I just ran into this problem. The issue is that when using more than one callback function, the return values are not processed as expected; the last function's result is what is used.
For example, imagine we want an object to be able to pass through spheres and boxes, but to hit heightmaps. Suppose we make a CollisionCallbackFn function that checks if the object is a sphere, and returns false if so, true otherwise. Suppose we make another CollisionCallbackFn function that checks if the object is a box, and returns false if so, true otherwise. Finally, suppose we make another CollisionCallbackFn function that checks if the object is a heightmap, and returns true. We CANNOT do as follows:
skin.callbackFn += new CollisionCallbackFn(TestSphere);
skin.callbackFn += new CollisionCallbackFn(TestBox);
skin.callbackFn += new CollisionCallbackFn(TestHeightmap);
Because only the last function's return value will be used! Thus, the return value of the final function called determines whether the object hits or not.
To fix this, change:
return callbackFn(skin0, skin1);
In OnCollisionEvent(…) in JigLibX/Collision/CollisionSkin.cs to:
bool result = true;
foreach(CollisionCallbackFn f in callbackFn.GetInvocationList()) {
result &= f(skin0, skin1);
}
return result;
Ian