Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Physics of a shelf

Discussion in 'Physics' started by dgoyette, Jun 1, 2018.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Here's a picture of a Shelf model I'm using:

    upload_2018-5-31_16-56-0.png

    The shelf needs a rigidbody on it, so that forces can knock it over. However, ideally each shelf would have a collider on it so that other rigidbodies could be placed on the shelf. This doesn't work very well, as Unity wants convex rigidbodies. I'm curious if anyone has any solution for having a rigidbody that contains multiple colliders. (I can't be the first person to make a shelf, though I realize maybe on most cases the shelf itself isn't a rigidbody.)

    Approaches I've tried:
    • Ignore the guidelines, and just put a bunch of box colliders on the object, one for each shelf, and two others for the sides. This sort of work, but the physics get really weird at times. Some of the colliders will go through the floor, and the object just gets stuck. So, this simple approach doesn't have good behavior.
    • For each collider, create a child object that contains the collider and the rigidbody, and a Fixed Joint connecting the rigidbody to another rigidbody. The result is pretty similar to the first approach, where it almost works, but then it kind of jumps around and behaves erratically.
    Do I have any other options? Or is this just beyond the capabilities of the engine?
     
    Last edited: Jun 1, 2018
  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    As you've tried, filling the graphics with box colliders is pretty much the way to go on this imo

    the rigidbody component should only be on the "root" game object, if you get a bit of jitter with this setup try and modify it a bit and or the physics setting.

    maybe post a picture with all the box colliders visible?
     
  3. trudeaudm

    trudeaudm

    Joined:
    Apr 17, 2013
    Posts:
    116
    You don't need child objects at all. You can add multiple box colliders to your object and just modify their size, and position. This shelve looks like it would have 9. Having child objects is nice for organization though, because you can name each child what it is for reference. Like "top shelf collider" and so on.

    Also just make one shelf then copy and past it, modifying its offset so you don't have to size it up each time.
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Here are the colliders; five horizontal colliders, and 2 for the sides:

    upload_2018-6-5_10-29-58.png

    Here's a video of the behavior. In this video, I have the shelf sitting in a room. Occasionally I fling it in the air to observe its behavior when it lands. This is done with a large vertical AddForce. You'll notice it wobbled around, and bounces erratically. (There is no physic material on any of the colliders, or on the floor.) Some times it hovers over the floor in a pretty weird way. The only time I'm moving the shelf is when it goes really high in the air. All the other smaller jumps are weird rigidbody behavior.

    I've tried uping the physics solver iterations as high as 20, but it doesn't seem to have any effect.



    Again, I expect this is probably somewhat expected behavior, as my understanding was that non-convex rigidbodies don't behave properly. But anyway, that's what I'm seeing when I have more than one collider on the rigidbody.

    At this point I've pretty much resigned myself to locking this shelf on the ground, rather than giving it rigidbody behavior.
     
  5. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    What setting did you try changing except the solver?
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    I tried adjusting Default Solver Iterations up to 20, and tried setting Default Solver Velocity Iterations to 20 as well, but neither stabilized the behavior. Here's what I have now:

    upload_2018-6-5_12-33-30.png
     
  7. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Try maybe playing with the contact offset and bounce threshold?

    I think adaptive force may change the behavior take note it may effect other aspects quite radically