Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug Can't get continuous collision detection to behave properly against static concave mesh collider

Discussion in 'Physics' started by camogamer, Oct 27, 2022.

  1. camogamer

    camogamer

    Joined:
    Apr 11, 2014
    Posts:
    3
    I have a fast moving rigid body hitting a smooth slope mesh collider that ricochets back some of the time. I know that there are many elements that can affect this and I have attempted to test every variable I could think of to get this to behave with limited success.

    ProblemGolf.gif
    A common example

    BallRicochet.png
    A worst case example

    In the current setup I have a sphere collider rigid body with continuous collision on and the transform is scaled to the size of a golf ball (0.0427m). the other collider is a static concave mesh collider built to scale. The ball is moved through addforce() as an impulse once when its hit. Things I've tried and considered:
    • swapping scale, both the transform and collider scale, and overall upping the scale across the board (same clipping occurred)
    • adding a rigid body with continuous collision to the mesh and making the ball have continuous dynamic (somewhere I saw that concave mesh colliders aren't supposed to work with this though)
    • tweaking many of the settings in physics both in the physics materials and project settings, although possibly not in a entirely complete way as I don't know on a fundamental level what they all do
    • adjusting the physics time step some, but I know this is generally just a bandaid
    • notably the ball's rotation is constrained, but I have tried with it unconstrained and had the same result
    • the averaged value of the physics materials on the ground and ball is 0.3
    I'm at point where I'm not sure if I've just done a bad job calibrating the physics engine, if I'm having some general misconceptions about continuous collision detection, or if this is an edge case. If I can't get this to function I'm left the options:

    Any insights are welcome, Let me know if I should provide more information. I need the mesh collider for another mechanic of the game to exist. I intend to commit mesh cutting atrocities which may cause their own issues after I solve this, but I have isolated that aspect for now. I'm using unity 2022.1.9f1
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,539
    That happens because your terrain is made of solid blocks, with thickness and vertical walls. In some cases the physics system detect a collision with the corner of the block, not just the upper plane, so it launches the ball upwards.

    upload_2022-10-28_13-53-14.png

    The solution is using planes for the terrain, or at least removing the vertical planes between two adjacent blocks. Also, ensure the colliders for these "blocks" are non-convex.
     
  3. camogamer

    camogamer

    Joined:
    Apr 11, 2014
    Posts:
    3
    Thank you for the reply, but in the image I supplied the mesh featured is whole and has only the single non-convex mesh collider so I do not believe this to be the source of the issues I'm observing. For clarification I also tested a striped down mesh with only the top faces to see if the results would be different but they were not.

    Example mesh.png
    The mesh without the sides or bottom faces
     
  4. vertexx

    vertexx

    Joined:
    Mar 18, 2014
    Posts:
    380
    Unity physics is like that. Sometimes ok then sometimes not, even in the very same areas! Seems very random as well.
    Was waiting for a reply to your query but as suspected...it's the way things are and always have been !
    We have to learn to live with it and experiment for best, not perfect results. Especially with colliders and rigid bods.

    Edit. Maybe this..
    https://assetstore.unity.com/packages/tools/utilities/better-bullets-220351
    might be of help? He has some comments on this and possibly a solution?
    The Physics tab also has some variables which might help too.
     
    Last edited: Nov 14, 2022
  5. camogamer

    camogamer

    Joined:
    Apr 11, 2014
    Posts:
    3
    So I've done some more research since I posted this and I can't say I've found a solution I'm happy with yet. Right now In the project I'm working on we decided to move forward with a huge increase in fixed time steps per second (from 60 to 180) as we don't anticipate needing too many rigid-bodies, not sure how well this will hold up of course. Here unity suggests that we should be getting impacts at the appropriate time, which in this case doesn't appear to be happening. I wonder how continuous collisions works in unity because most physics engines (all?) conceptualize sub steps and will have a settings for max steps, physics x is no exception, but we don't have this setting exposed. I did attempt the contact manipulation method and the state of the data during the event explained why the resolver was throwing the ball back, but the error had already occurred and could not be corrected at that point. I haven't tried bullet physics because I suspect that this problem could be caused by my own misconceptions and with the physics update rate increased the problem is minimized. If it comes to it and I must attempt the swap to bullet (which has a package for unity, though it may be old) I intend to share those results.
     
  6. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,980
    In case you're using speculative CCD, this is a known (and expected) issue, illustrated in the manual with an example almost identical to your use case:
    https://docs.unity3d.com/Manual/ContinuousCollisionDetection.html

    This is inherent to the way speculative collisions work in most engines. Using sweep-based CCD should get rid of (or at least alleviate) the problem.
     
    karliss_coldwild likes this.