Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Physics - Moving shopping carts like in the real world - Is it possible?

Discussion in 'Animation' started by danielesuppo, Aug 28, 2022.

  1. danielesuppo

    danielesuppo

    Joined:
    Oct 20, 2015
    Posts:
    331
    Hello all, I'm very new to Unity physics and I have a very annoying problem:
    I should be able to move a shopping cart inside another one, next to move both into a 3rd one, a 4th one, etc, just like if you were in a market and you tried to put all the shopping cart here and there in a row, and bring them back to their place.

    Actually I've created a very very simple scene with a super stylized model, just for test purpose:


    Ideally it should be quite easy to realize in several softwares, but in Unity it's becaming a nightmare, because:


    1) The first challenge I had was to create a Concave collider for my super stylized shopping cart model:
    the "Mesh Collider", if it's not "Convex", does not support "RigidBody" if it's not "Kinematic".
    So in Blender I had to create the model, plus 4 boxes (left/right/front/top) just as colliders to use them as "Convex".
    Moreover I had to do a trick to put a "RigidBody" component on the Parent Gameobject (using a fake small plane), just to be able to activate the Physics in the hierarchy of the model o_O


    2) Next, when I've applied a "Mesh Collider" to the collider boxes (created in Blender) the cage didn't retain the shape of the box.
    It's a too rough approximation with 5 vertices (instead of 8), so the real width of the boxes is not taken in account for collisions.
    I can't either use some "Box Collider" to replicate my model, since it's not possible to rotate them... :mad:



    3) Anyway, I keep on my experiment.
    I think should use "RigidBody.AddForce" in place of "Transform.Translate" to move my 1st shopping cart (the one that I directly move with the keyboard), because for what I've read it's the only way the get good RigidBody calculations in Unity (indeed, with "Transform.Translate", if the 1st shopping cart move a bit too quickly it does not collide anymore with the others, despite any RigidBody option (Interpolate, Continuous Dynamic), and generally the physics calculations are quite weird).

    So I try to in this way, but I forgot to put my 1st shopping cart as Kinematic :confused:



    4) Well, the movement/rotation of the 1st shopping cart (the one that I directly move with the keyboard) should not be influenced by the others, so in my idea it's RigidBody should be set to "Is Kinematic".
    But in this way "RigidBody.AddForce" does not work anymore :rolleyes:
    It should not be a big issue, I can move it with "Transform.Translate" (much more easy to manage), but in this way the RigidBody calculations does not work well anymore, because for what I've read I'm breaking the physics laws since I'm moving an object just like with a Teleport, and the force of the object is not taken in account anymore :confused:



    5) Well... is it possible to realize this kind of dynamic?
    I know that I'm not actually using a rigged 3d model for test (with weels, etc), and the behaviour will be much different for sure, but if the basis is not working as expected I think there's a big problem, expecially for me to understand how it work.
    Any help on it would be much appreciated
    Many thanks!
     
    Last edited: Aug 28, 2022