Search Unity

How can you get an exact CONVEX mesh collider?

Discussion in 'Physics' started by g-hoot, Mar 23, 2017.

  1. g-hoot

    g-hoot

    Joined:
    Apr 18, 2015
    Posts:
    69
    Hello all,
    I'm trying to set up a forklift when it can be operated using The HTC Vive Controllers. I have played with hinge and spring joints and had a lot of trouble. For example, I want the steering wheel to rotate about it's axis, so I set up a hinge joint for that. The steering wheel has a knob, so I added a sphere collider to it and a spring joint to join at that point to tie to the Vive Controller to steer it. Kinda works, but finding the right balance between the hinge joint settings and the spring joint to keep from pulling it off of it's axis is almost impossible. Also, when I drive the fork lift, the momentum moves the steering wheel off of it's axis until the forklift stops.

    So, I thought no problem. I went back into SolidWorks and modeled the steering wheel to fit in a hole in the steering column so I can just use physics to keep it in the hole. Well, after bringing it back in, I found that Mesh "Colliders" don't actually collide unless you change them to convex. Problem is, after you do that, it simplifies the mesh so that there's no hole for the shaft on the steering wheel to go into.

    I'm wondering what good convex mesh colliders are, if they don't keep the actual mesh of the model? isn't that the whole point of a Mesh Collider? Is there a way to get the true mesh as convex? I have several areas where this is needed, like for each handle, they have a pin going through a hole that I need them to pivot on. And the fork assembly needs to be able so slide up and down in it's grooves. I know I can add compound colliders, but that is going to be a tone of work.

    Any help is MUCH APPRIECIATED!
    Thanks!
     
  2. Svenberra

    Svenberra

    Joined:
    Nov 5, 2012
    Posts:
    4
    Well, the thing with a convex mesh collider(convex hull) is that it must be convex. No holes or any concavities what so ever.

    What you need is something called approximate convex decomposition. That is a process that generate a compound collider with lots of convex hulls based on a mesh.
    It's currently on the Unity Roadmap.
    So you either have to wait for that, implement it on your own(google for V-HACD) or manually create the compound collider.
     
    Last edited: Mar 24, 2017
  3. g-hoot

    g-hoot

    Joined:
    Apr 18, 2015
    Posts:
    69
    Thanks for the information! So, I guess it's not possible to use a non convex mesh for collision physics then?
     
  4. g-hoot

    g-hoot

    Joined:
    Apr 18, 2015
    Posts:
    69
    After re-reading some of the Unity info, it sounds like a non convex mesh can be used with physics as long as it isn't colliding with another non convex mesh. This may work. Then I could leave items with holes as non convex mesh and add a capsule collider to the other part for the pin in the hole. Gonna go play with that for a while.
     
  5. g-hoot

    g-hoot

    Joined:
    Apr 18, 2015
    Posts:
    69
    Well, the non convex mesh seems to be completely ignored. So, I set the steering wheel up like this:


    And the steering column up like this:



    And it works if I move the wheel very slowly. If I move it very fast, it pops out and floats off into space. I tried setting all Rigid Bodies to Continuous and Continuous Dynamic and still get the same results. How do people usually handle something like this?
     
  6. g-hoot

    g-hoot

    Joined:
    Apr 18, 2015
    Posts:
    69
    I went back to joints. Did a Configurable Joint and then change the Angular Drag on the Rigid Body to 5 and added several colliders. This is working fairly well. Open to any other suggestions for sure!

     
  7. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,521
    Unity Physics kinda break down when you try to use it for anything moderately realistic, especially like keeping things in holes. It has an extremely hard time doing stuff like that and it's nearly impossible if you have external non-physics forces somewhere in there. Once a collider goes inside another collider, or something is slightly out of whack its going to go totally ballistic without significant intervention to control things.

    Lock the steering wheel to a position and only let it rotate on one axis. Forget the steering column. Use long rectangular box colliders to wrap around the steering wheel instead of spheres, like a lowpoly tube.

    You can significantly improve the physics simulation by changing the Physics Settings (Edit>Project Settings>Physics). Default Solver Iterations and Default Contact Offset make the biggest impact. I think that is the least of your worries though as the problem seems to be you are going about doing this the hard/wrong way.
     
  8. g-hoot

    g-hoot

    Joined:
    Apr 18, 2015
    Posts:
    69
    Thanks for the feedback LaneFox. The Configurable joint let me lock it down to just rotating in the y axis. That is working pretty good. I like your idea of the long box colliders. It can get kind of "bumpy" rotating the steering wheel with the sphere colliders, but other than that, it's working decent now.

    I know I'm doing it the hard way alright! LOL What's the easy way?