Search Unity

Shopping cart

Discussion in 'Physics' started by Sheprekt, Jan 27, 2020.

  1. Sheprekt

    Sheprekt

    Joined:
    Dec 11, 2017
    Posts:
    9
    Hello physics people. I have some questions. I have this beautiful shopper and his shopping cart. (Fig1 https://i.imgur.com/Vjt1jYo.png) I'm moving him around my level with addforce - so he needs a rigidbody, and I want to be able to have items in the cart. Unfortunately, none of the primitives allow for this, and you can't use non-convex mesh colliders with a rigidbody. As a result, I've set up 5 box colliders around my cart on separate game objects for each side and the floor. (Fig2 https://i.imgur.com/uXY6TGo.png). So, with that context, some questions:

    - If I drop some primitive shapes with rigibodies into my cart, they work as expected, until I start moving around the level. It would be fine if they escape out of the cart through the open top, but they often fall through the walls of the cart itself
    - The movement when I had a single box collider for both the player and the cart was much better, but now I have a bunch of colliders as child gameobjects, it barely moves around anymore with rb.AddForce.
    - Essentially I want the cart to move around the level, and to be able to contain items that also move around the level

    Really struggling to get Unity physics to behave here so open to any suggestions or better ways of achieving this.

    Fig 1


    Fig 2
     
    Last edited: Jan 27, 2020
  2. knobblez

    knobblez

    Joined:
    Nov 26, 2017
    Posts:
    223
    If you want to keep it how it is and just get the car moving, either increase the force or decrease the mass. But it sounds like you first, need to figure out why the objects are falling through the bottom.

    If the items are bouncing around a lot in there and are pretty heavy then maybe you need to decrease the mass and gravity effect on them.

    Increasing the collider width of the cart would probably help. From my experience, if the items pass the collider they can fall through.

    What do the rigidbody settings look like? Both for the items and for the cart