Search Unity

Sphere collider propelled off of mesh collider

Discussion in 'Physics' started by rbOthree, Sep 23, 2017.

  1. rbOthree

    rbOthree

    Joined:
    Oct 16, 2010
    Posts:
    67
    Hi,

    I have a sphere collider that has a velocity applied to it. The velocity is parallel to a mesh plane that the sphere collider is idle on. At one point on the mesh (each time seemingly random) it shoots off in a random direction.



    This is a view from the side where I have a trailer renderer (purple) showing its path. The red line shows the intended path.



    This is from another perspective showing that the sphere actually travels in quite an odd path in the air after it randomly deviates from the mesh.

    The reason it is a mesh instead of a plane (and why it has so many triangles) is the mesh is actually procedurally deformed. For this example I flattened it completely to quickly test, hence triangles for no reason. It does represent what would be the final form in areas with flat plains.

    The velocity of the sphere isn't relatively that large, it usually happens about 0.5s in to the travel.

    Any help here is appreciated. Let me know if any material/mesh properties will help.
     
  2. rbOthree

    rbOthree

    Joined:
    Oct 16, 2010
    Posts:
    67
    So after some continued testing and some digging, I'm thinking it may be something to do with the sphere collider passing over mesh seams. My screenshots above don't really show it deviating at a seam, but I'm thinking it may be because of my physics settings being continuous.

    Unfortunately, I can't easily remove the mesh seams as the size of my allowed meshes are constrained. I'm also using different meshes to simulate different physics materials.

    Generally people seem to have solved this by reducing the default contact offset or increasing the amount of solver iterations. I've tried these settings without much luck. I can definitely reduce the occurrences, but never completely eliminate it. My current settings are:

    Sphere:
    Interpolate: None
    Collision Detection: Continuous
    Mass: 0.1
    Drag: 0
    Angular: Drag 1

    Physics:
    Contact Offset: 0.01 (tried down to 0.0001)
    Solver Iterations: 6 (tried up to 100)
    Velocity Iterations: 3


    Are there any smarter ways I can generate my mesh to to reduce the effects that seams create?
     
  3. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    Total shot in the dark here:
    Does it help at all if you overlap your ground segments by a row of triangles? Maybe the seams are only issues because the adjacent sections aren't actually touching?

    Also is your mesh constraint hardware related? If not, can you generate the ground via code instead of pre-generated meshes that are instantiated and manipulated?
     
  4. rbOthree

    rbOthree

    Joined:
    Oct 16, 2010
    Posts:
    67
    Apologies for the late reply, didn't get an email about a response!

    Definitely an interesting idea. Unfortunately I just tried it and the sphere still does it. It doesn't seem to be where 2 edges touch, just when it "rolls" over an edge.

    All of the meshes are produced via code.

    Currently they were split to avoid myself going over the vertices limit for one mesh, and to allow me to have multiple physics materials. I can get over the physics material and just simulate this myself, but unfortunately combining the meshes puts me over the vertices limit. I'm at a bit of a loss as to how to "hide" these seams.
     
  5. Plystire

    Plystire

    Joined:
    Oct 30, 2016
    Posts:
    142
    I see... in that case, can you position the material seams slightly lower than calculated? Combined with the overlapping section, you can have the "continuous vertices" touching and producing a flat surface, while the seams will be underneath and not touched by the sphere.
     
  6. rbOthree

    rbOthree

    Joined:
    Oct 16, 2010
    Posts:
    67
    Hey,

    Do you mean something like this?



    Or something of the equivalent where every edge is still touching?

    I'm not entirely sure that will still work. In some of the questions I've seen asked on these forums I've seen people complain about the same problem with box colliders stacked perfectly next to each other. I'm not sure it is the literally edge of the mesh, but instead the fact that there are 2 colliders affecting one collider. Does that make sense?

    I can try it out anyway, I thought I'd confirm before.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    What kind of collider is it? convex etc? Also unity version.
    How about scale?

    Mass: 0.1 kilograms? These problems typically arise when throwing a house with the mass of an apple at the speed of sound, even if it looks normal in the air.

    Personally I suspect the collider of what you're making isn't what you are expecting. Physx can and does manage seams fine, given a little mass to work with.
     
  8. rbOthree

    rbOthree

    Joined:
    Oct 16, 2010
    Posts:
    67
    Hah! That is very possible.

    The collider on the mesh is not convex. It is a completely default mesh collider.

    For the sphere, I'm using a sphere collider.

    Mass 0.1
    Drag 0
    Scale 0.04 on all axes
    Collider Radius 0.55

    I also logged my velocity to see if it did anything weird, it did. Velocity magnitude starts off at about 15 when the sphere is "hit". Drops to about 6 before shooting back to about 10 (when it hits a seam).
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I meant the collider on the 'terrain'... this is likely your problem, it might not be what you're expecting it to be. For a start it probably won't work set to convex because this is limited to 255 triangles. Next up, this means logically, you're using a normal mesh collider that is not convex.
     
  10. rbOthree

    rbOthree

    Joined:
    Oct 16, 2010
    Posts:
    67
    That's what I meant here. I realise my terrain collider is not convex, why would this pose a problem?
     
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Your terrain collider should not be convex. Ideally it would use heightmap collider, or terrain collider (a physx heightmap collider in disguise) https://docs.unity3d.com/Manual/class-TerrainCollider.html

    However due to Unity's crappy implementation we can't really set it without a terrain. You can still use it but you would have to hide the terrain. This increases memory consumption but a small amount, it's not that bad, and it doesn't need to render. Still, it's inconvenient to set up.

    So if you are using mesh collider, can you confirm your unity version and how many triangles the mesh has?

    Regardless, mesh collider is slow, and gets slower the more complex the mesh is. I'm pretty sure it'll bug out on meshes with vast poly counts, requiring you to split the collider mesh or use another approach.

    If the problem is none of these, you're best served upping a bug report.
     
  12. rbOthree

    rbOthree

    Joined:
    Oct 16, 2010
    Posts:
    67
    Hi,

    I'm currently running 2017.1.0f3. The meshes have <200 triangles since I'm splitting them up frequently.

    Speed isn't my current issue.

    I'm not entirely sure this is really a bug, I do understand what causes things like this to happen. Either way, I'd like to find a way around it apart from submitting a report and waiting however long it takes to have it addressed.

    This is definitely a common problem with closely aligned colliders, I'd just like to find out how other people have approached this problem.
     
  13. FirstTimeCreator

    FirstTimeCreator

    Joined:
    Sep 28, 2016
    Posts:
    768
    The physics material can make a big difference if your collier is hitting seams or corners. You want it to bounce a bit otherwise a constant collision will cause a problem and cause it to fly through whatever corner it is hitting. Also adjust your friction, it looks like you need to lower it so it doesn't catch and fly off, instead it will slide.

    Also your angular drag will control how fast the object can rotate to shoot in a certain direction when it hits a slope. Angular drag, and friction is what you need to adjust.

    Unity's physics engine works pretty well, look at what I am building: