Search Unity

[REPOST FROM GRAPHICS - WRONG FORUM] Brainstorming solutions: "Aligned flat mesh, rolling ball skip

Discussion in 'Physics' started by Tset_Tsyung, Dec 10, 2017.

  1. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    Hey all,

    In my current simple project I have various tracks (over different scenes) where the player has to guide a ball to the end using different magnets they can turn on and off. I create the tracks using simple 'pieces' that I've made in Blender that are then placed beside each other (think childs train track...).

    The game is working fine, except when the ball is travelling at speed. At certain speeds the ball will clip the mesh colliders at the joining of the various models (will discuss below) and either act as if it has hit a wall or a small ramp propelling it through the air.

    This is a common problem that we have all faced at some point in our Unity (if not game making) history. And sometimes none of the answers provided by Google actually solve the issue.

    What I've tried so far (based on googled solutions):
    1. Adjusting the solver iteration from 6-30 (or even 50).
    2. Taking all the meshes used in the level and creating a combined mesh with them, then disabling the individual mesh colliders and simply using the 1 large mesh collider.
    3. Adjusting the Rigidbody of the ball to 'Continuous Dynamic' and 'Extrapolate'.

    What I've yet to try (starting tomorrow):
    1. Taking all of the items used to piece together the levels and build them into one solid object within blender. However I don't want to do this as this mean that EVERY single change I make to the courses will require adjusting in Blender, exporting and re-importing. Also I'm not sure how the complicated meshes will be handled within Unity. It will be an interesting experiment anyway...
    2. Take the objects and strip them down to even simpler parts so as to use primitive colliders instead of mesh colliders. Again, not sure I want to do this as I'm unsure if primitives will fair any better after I place the various objects right next to each other. Question: Does the Unity Physics systems address primitives differently to meshes, so that this problem might not occur?
    Although I've been learning Unity for nearly 2 years now (health problems slow down progress time to time) I'm well aware that there are major holes in my knowledge - collision detection being one of them. I have started looking into the 3D maths involved (basic mesh slicing) but I'm well aware that there is plenty more complicated processes involved.

    Sorry - this has turned out longer than I originally wanted, but would love to hear what you have come up with to get around this issue, if this is a fringe issue that you have all 'outgrown', and if you know of any great resources for learning more and physics collision detection (from laymans view upwards).
     
  2. FissicsPeep

    FissicsPeep

    Joined:
    Jan 14, 2014
    Posts:
    80
    I've been seeing similar issues when trying to make a mini-golf game (using tiles for the course pieces)... the rolling ball collides with the edges of each piece. Not only that, I'm seeing it collide with individual triangles within a mesh:



    The green lines in the above are the triangles of the mesh... but it's just a flat surface here. The ball is bouncing and I'm rendering the contact normals it gets during collision. As you can see, when the ball is bouncing on these triangles, it is colliding with 2-3 of them at the time and getting normals as if it had hit the edge of the triangle.

    Really in this case, it should be a combined flat surface and the normals returned should all point directly up.

    I've seen the issue you speak of in a published mobile golf game too. If you aim at the joins between tiles, the ball can bounce back at you, rather than "reflect" off the surface.

    I would also love to know how to solve this. I am aware that in Unreal Engine 4, you can get a callback DURING the collision processing and you can modify the normal (and other collision properties). In this case, you could modify the normal based on your own calculations to always return the correct one. Unfortunately however, Unity does not expose these callbacks:

    https://feedback.unity3d.com/suggestions/physics-contact-modification
     
    Tset_Tsyung likes this.
  3. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    The only other solution that comes to mind is learning how the entire physics engine works (no small task for a beginner like me), and possibly even make my own.

    But surely this is a problem that many developers encounter and overcome... This must be a basic issue that plagues most games somehow [he says, not understanding a thing he's talking about].

    At this point I'd be happy for someone to say "Here! Read this book, and don't return until you understand it all" - no seriously, that would be really helpful! XD
     
  4. Deleted User

    Deleted User

    Guest

    MeshCollider is going to struggle without a clean collision mesh. You know that's awful, so, like, start with that. I don't know what's going on with that mesh, but it's no good. I copy my meshes and make simplified versions of them to feed MeshCollider to prevent this.
     
  5. Tset_Tsyung

    Tset_Tsyung

    Joined:
    Jan 12, 2016
    Posts:
    411
    @JayMounes
    Many thanks for the reply. In my project I'm using low poly simple shapes made in blender for the object mesh AND the collider mesh. Would MeshCollider still struggle with these? [See pic]

    MeshColliderIssue.PNG

    If it would still struggle, would it be better (as in less/no ball skipping) if I removed as many MeshColliders as possible and replaced them all with primitive shape colliders?

    Please note: Due to the simple nature of the meshes, and the fact that this game doesn't have much going on CPU wise, I have ALL track parts set as MeshCollider... wondering if reducing those for some of the super basic shapes might help... will experiment and get back to ya
     
    Last edited: Dec 13, 2017
  6. FissicsPeep

    FissicsPeep

    Joined:
    Jan 14, 2014
    Posts:
    80
    That mesh looks overly triangulated as there's a hole in the centre (golf tile), so the triangles are from that.