- Home /
How can I keep small dynamic physics objects from occasionally falling through a mesh collider?
I have a physics simulation where dynamic objects fall across a relatively complicated object represented by a mesh collider.
Generally everything is working fine, I've had my fair share of problems and dabbled with the fixed timestep to try and stop higher speed collisions from failing as an object passes through a surface in the space of one frame. I'm on Unity iPhone though so its not easy to give too much cpu time to the fixed updates.
I am getting a problem now where by every so often my dynamic objects will either fall straight through the mesh collider or occasionally settle for a while, and then fall through the mesh it was previously settling on.
I've been dabbling in the editor where i can even see this happening and notice that all i have to do is move the mouse across the dock to cause it to animate, the framerate drops in the editor to around 20fps and typically the objects will fall through the mesh collider.
I presume that the objects are managing to pass through collider again in a frame as the framerate is dropping so far, though surely the fixedupdate should be insulating it from this. I know there is a max fixed timestep that can be set, to a maximum of 0.3333 but what happens if this time limit gets reached, surely it shouldn't cause any issues.
Finally i know scale can play a role in this, the mesh collider is about 1m or so across, with the dynamic objects being about the size of a coin. I've heard the physics system's not meant to like smaller objects, but i decided to try and make the scale about lifelike so as to make gravity feel more correct.
I'm thinking now though that perhaps the size of the dynamic object is perhaps quite close to the largest distance it could move in a fixed update, perhaps this is causing it to be more likely to fall through a simple thin polygon more easily. I can't quite figure out if i increase the scale of it by say 10 or so, getting the dynamic objects closer to 1m then would the size of the object still have the same relationship to its maximum distance moved in a fixed update if i make the velocities match up by eye.
Beyond all this i wonder if trying to put a box collider floor underneath my mesh collider may be more of a failsafe as being less thin it should be far less likely to fall through in a frame.
What are people's strategies for handling this kind of problem? Especially with the CPU power of the iPhone.
Cheers
Answer by StephanK · Feb 16, 2010 at 12:26 AM
IMO the best strategy is to "reinforce" thin meshes or planes with extra, invisible colliders behind them, as you suggested, if that's possible. (Only possible with meshes where collisions do not occur on opposite sites.) Depending on how much colliders you have in the scene and how complicated the meshes are, you could also try to take this into your own hands and doing raycasts in an object's velocity direction and then check if the velocity is high enough, that in the next frame there would be a collision and react to it accordingly. Not very pretty, but if you don't have lots of objects this should work quite good.
Thanks. I do wonder about doing this.
I also realise now that for the settled problem the size of the dynamic object/sphere may be important, ie. its far easier for a smaller object to pass through the super thin polygon where as a larger object would hopefully have more time intersecting the polygon to react. Though to make it look similar sometimes the gravity acceleration needs increasing as the scale increases. Not sure if the two were increased equally whether it would be any different at all? Usually you dont need to match the scale increase so i guess this is where the improvement is.