For a ball & maze game, we have a ball rolling around on a mesh with pathways. But we are running into some very disappointing physics collider performance, which all but renders things unworkable.
I’d like to understand if we are doing something incorrect, or if this is expected performance of Unity and PhysX. So I’ve set up a super-simple app to demonstrate a basic problem of ball falling through collider. It is simply…
- a primitive Cube ‘platform’ with Mesh Collider at scale=[50,1,50], with Rigidbody configured as Kinematic, set to ‘Continous’ Collision Detection.
- a primitive Sphere ‘ball’ @ scale=[2,2,2] with Sphere Collider, and Rigidbody configured for ‘Continuous Dynamic’ Collision Detection
The platform is tilted via mouse input (rotation is applied in FixedUpdate), and the ball simply rolls around on the platform.
RESULT: It is fairly easy to tilt the platform abruptly (although it’s not all that fast) and cause the ball to fall through.
I have spent many hours experimenting with different scales, Time and Physics settings (Fixed Timestep, Solver Iteration Count), mesh vs. box collider, Rigidbody settings (mass, etc), different thickness surfaces, etc. But without much success. I can improve the performance a little in some cases, but never to a reasonable level. I am using Mesh Collider instead of Box Collider on the platform, to mimic what we must use in our game (the improvement is not significant with a Box Collider, ball still falls through). Many in the community suggest cranking up Solver Interation Count to 100, or cranking down Fixed Timestep. But I’ve found only partial benefit from that. Actually, I’ve found that in some cases, more Solver Iterations gives worse results. In all the combinations I have attempted, the ball falls through with rather disappointing consistency.
Currently the tilting ‘platform’ is kinematic, and as per the Unity docs I am using standard transform.rotate function to manipulate. I received some feedback that I should be using Rigidbody.MoveRotation, which seems to contradict the documentation, but I tried it and it does improve the collision performance some. However the ball still falls through when the platform is tilted quick.
I am aware of the “DontGoThroughThings” script at the wiki, and I really appreciate the efforts of those who developed that. But the thing is, I’ve got a relatively slow-moving ball rolling around on a relatively-slow tilting surface. It’s not a fast-moving projectile like is typically problematic. So, why should it be necessary to implement an extra helper script, when we have this supposedly-world-class fancy PhysX engine under the hood? And this is using the Continuous Collider functionality? (which I observe makes little or no difference… it actually causes the ball to bounce uncontrollably at smaller scale values)
HERE is a Unity package with the basic test scene. It is updated with two platforms, one using rigidbody.MoveRotate (left), and one using transform.rotate (right). MoveRotate definitely improves collision (left platform), but a fast tilt of the platform still causes the ball to fall through. (wait for it to roll out towards the edge, then give the platform a quick tilt up)
Is this the expected collision performance of Unity and PhysX? If anyone can offer any suggestions, it would be greatly appreciated. Thanks…
Whilst not a solution to your problem, try: http://files.unity3d.com/graham/Roll-a-Ball4.0.zip which shows a similar game. I don't remember this demo doing anything special regarding physics.
– Graham-Dunnett