Search Unity

Bug Contact welding collision goes crazy

Discussion in 'Physics for ECS' started by hauwing, Apr 7, 2021.

  1. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    69
    Hi

    Just created a cylinder (shape type is mesh) to roll down a spline track (shape type is mesh) and terrain (converted to mesh shape), have set Havok config to use contact welding and set the tag to the track and terrain, the cylinder just went crazy. If set the tag back to "Nothing" (no welding) things went back to normal except for the bumps when going through edges. Please see the video. Thanks.

    Unity Version : 2021.1.1f1
    Havok : 0.6.0 preview 3




    upload_2021-4-7_22-29-42.png
     
  2. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Hmm, strange to see so big impulses applied when welding is on. How does the mesh look like, does it have holes or strangely positioned triangles?
    I suspect there's something with the mesh(es) that doesn't play along well with physics (and welding) and investigating that requires a closer look, so could you please send a minimal repro project?
     
  3. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    69
    Thanks,

    Please download the project folders below. There are 2 cylinders, the red one is using my own mesh, the yellow one is using the built-in cylinder shape. The red one just goes crazy while the yellow one behaves much better, but still there are some minor bumps here and there. The cube just there as a reference to show that contact welding is taking effect. My feeling is contact welding works fine for sliding but not for rolling.

    https://drive.google.com/file/d/1tAzKgs7o_clauN_DYl2m-au3p2Bwv0if/view?usp=sharing

    Thanks.
     
  4. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    If the cylinder is shape type mesh then you are colliding triangles against triangles, so I'm not surprised this is weird. Was that a typo? Why not simulate the cylinder as a shape type cylinder?
    Also make sure your Bevel Radius is not zero. The default should be fine if the cylinder is about 1m tall.
     
  5. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    69
    As mentioned earlier, the yellow cylinder is already in a cylinder shape, if you look closer at my project (download link), you will notice that the bumps are not due the triangle collision where it should have a stable frequency due to the polygons of the mesh, as you can see, it just jumps by itself without a fixed pattern. Also, it seems like increasing the solver iteration count will exaggerate the jumps rather make it more stable.

    Bevel Radius is 0.05 by default, but the height is 2.7 - does it matter?

    For comparison, I have also added a new purple cylinder using the existing Unity physics, and use the same cylinder mesh with mesh collider, and duplicate the same terrain mesh also with mesh collider, it just rolls smoothly and can keep in a straight line for a decent distance.


     
  6. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Hi @hauwing , thanks for the repro project. Have you noticed that everything works much better when Terrain is disabled and cylinders roll down the spline1 object?
    That indicates there's probably something wrong with terrain. I didn't find anything obvious on first look, mostly because it's huge and editor doesn't work smoothly when "Draw Collider Edges" is checked in Physics Debug Display.
     
  7. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    69
    Hi @milos85miki , yes using the spline alone is much better, but if you look closer, you can still see jumps here and there, just less frequent compared with terrain. In fact the spline mesh is the first place I found the issue.

    The terrain mesh is just converted from a standard terrain using the following tool:

    http://wiki.unity3d.com/index.php?title=TerrainObjExporter

    Actually my intention was not to use a mesh as collider, I did try to use the TerrainCollider in the new DOTS Physics but the situation is even worse, so I have no choice but to use a mesh instead. Please see my another post here:

    https://forum.unity.com/threads/using-unity-terrain-with-dots-workflow.755105/#post-7004405

    Please be reminded that the terrain mesh (and also the spline mesh) works very well in the existing built-in physics system, so I can't really tell what's wrong with it. Thanks.

    Maybe I will prepare another smaller terrain for your testing later if you like.
     
  8. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    I've taken a closer look at this and I think we broke welding somewhat in the Havok Plugin when we moved to the latest version of the SDK. In the short term, given that your meshes are really clean you could use the general c# version of mesh triangle welding from the ModifyNarrowphaseContacts demo and I'll get back to you with more info on the Havok specific side fix. Note that this modify script works for Unity or Havok simulation backends.
     
    Last edited: Apr 15, 2021
  9. hauwing

    hauwing

    Joined:
    Dec 13, 2017
    Posts:
    69
    Hi @steveeHavok, I tried using ModifyNarrowphaseContacts on a mesh collider (a mesh generated from a terrain), when I placed some objects on that mesh collider, there are still jumping and drifting occasionally. It is more obvious when I increase the solver iteration count to something like 30. (default 6 is not stable enough). Turning off ModifyNarrowphaseContacts will become normal. Will this issue be addressed altogether?
     
  10. RedClawStudios

    RedClawStudios

    Joined:
    Apr 23, 2015
    Posts:
    6
    Hi, upgraded to 2022.2 ... game has been stable since 2018 now colliders all stopped working, all surfaces and characters. No collisions get detected or trigger.
    Super frustrating.
    Resetting does not seem to work, where is the read / write setting please? Can't find.
    Not good QA.
     
  11. JMPM-UNITY

    JMPM-UNITY

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    93