Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Simple Collider Test Failure - Sphere Falls Through Mesh

Discussion in 'Editor & General Support' started by grojguy, Apr 30, 2013.

  1. grojguy

    grojguy

    Joined:
    Jul 13, 2009
    Posts:
    35
    We're using Unity to develop the first in a series of puzzle games. Often a puzzle involves a ball rolling around in/on a mesh. Not far into development, we are running into some very disappointing physics collider performance, which essentially 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 simple...

    - a 'platform' (scale = 50x1x50, primitive Cube with Mesh Collider, and Rigidbody configured as Kinematic, and 'Continous' Collision Detection)
    - a 'ball' (scale=2x2x2, primitive Sphere with Sphere Collider, and Rigidbody configured for 'Continuous Dynamic' Collision Detection).

    The platform's tilt is controlled via mouse (rotation is applied in FixedUpdate), and the ball simply rolls around on the platform.

    http://bit.ly/18axHmB
    $Unity collider test 1.gif

    Result: It is very easy to tilt the platform and cause the ball to fall right through.

    I have spent hours trying to get collisions working for our game, experimenting with various scales, Time and Physics settings (Fixed Timestep, Solver Iteration Count), mesh vs. box collider, Rigidbody settings (mass, etc), different thickness surfaces, etc. But to no avail. I can improve the performance a little in some cases, but never to a reasonable degree. Note that I am using Mesh Collider instead of Box Collider on the surface, as that's what our game must use, and the improvement in performance 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 disappointing ease.

    And I do know about the "DontGoThroughThings" wiki script, and I appreciate the efforts of those who developed that. But come on, we're talking about a slow-moving ball rolling around on a relatively-slow tilting surface here. Not a fast-moving projectile or something. Why should we have to implement that kind of script when we have this supposedly-world-class fancy PhysX engine under the hood?

    Alas, I hope the answer is that I am overlooking something. Surely this cannot be the actual expected performance? I am attaching the simple demo app package in hopes that a UT person or super-smart community guru will be able to shed some light on my predicament. I really need help, and would greatly appreciate it.
     

    Attached Files:

    Last edited: Apr 30, 2013
  2. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,740
    In the attached sample you move the transform directly. That causes a physics conflict that has to be resolved, sometimes that will cause the ball to fall through.

    The correct way to achieve the results you want is to manipulate the transform through the rigidbody which can properly notify physX about the change and have the physics system handle it correctly.

    I suspect replacing
    Code (csharp):
    1. transform.rotation = action;
    with
    Code (csharp):
    1. rigidbody.MoveRotation(action);
    should work for you. But it was impossible for me to reproduce your problem with my mouse.
     
  3. grojguy

    grojguy

    Joined:
    Jul 13, 2009
    Posts:
    35
    Thank you for the fast reply, UnLogick, and for your suggestion. However, as a result I am a bit confused, considering this excerpt from the Unity Reference docs...
    And from the Scripting Reference...
    From that documentation, I thought it quite clear that Kinematic rigidbodies are to be manipulated through standard transform operations. Am I understanding this incorrectly? If so, it seems that maybe there is some possible lack of clarity in the documentation.

    I tried that simple change to rigidbody.MoveRotation, and it did help significantly. However, the ball still falls through the mesh, with slightly faster tilting of the mesh. Decreasing Fixed Timestep value does also help, but still there is fall-through.

    Concerning Collision Detection mode ... can you clarify, in this scenario, with the ball (primitive Sphere Collider) set to Continuous Dynamic.... if I select Continuous or Continuous Dynamic on the Mesh Collider (which is NOT static), will this yield more accurate collision? Or do the Continous Collision modes only work on static mesh and primitive colliders? This is not explicitly clear in the docs, that I can find.

    Thank you....
     
  4. grojguy

    grojguy

    Joined:
    Jul 13, 2009
    Posts:
    35
    Mozes, thank you for the response. I tried the Convex option, and it resulted in same or worse performance.

    According to the documentaton, the Convex option is not applicable here. Convex allows a Mesh Collider to collide with other Mesh Colliders. This does not apply in this case, since the sphere/ball is a primitive Sphere Collider (colliding with a mesh collider - the table/platform).
     
unityunity