Search Unity

Trouble with realistic Fork Lift Physics

Discussion in 'Physics' started by rick-phillips, Oct 18, 2018.

  1. rick-phillips

    rick-phillips

    Joined:
    Sep 23, 2012
    Posts:
    4
    I've been trying to replicate controlling a vehicle like the one below, not far from a fork lift but a little more complex in its movement. This is a question in the form of a short story...


    I've simplified the movements required to the following setup;

    https://imgur.com/GCyRDPQ

    I got the movements working exactly how I wanted to by moving transform positions/rotations directly for the three movement points (A, B and C in the image) and having one rigidbody for the entire vehicle. The problem here was that there was no drag being applied to the load so it wouldn't follow the forks realistically, and slide off. After some googling I learnt moving transforms directly doesn't effect physics correctly and I would have to use rigidbody.MovePosition and rigidbody.MoveRotation. I tested this by adding a rigidbody to the load and moving it around. I found with this the load moves with the fork assembly as it should.

    From here, I made the rigidbody kinematic (otherwise gravity would send it to the floor) and linked it to a transform at the end of the boom assembly. This solved the unrealistic sliding off of the load but introduced the problem of the forks passing through the floor as the kinematic rigidbody would ignore it. My conclusion from this is that the rigidbody must be non-kinematic.

    Here began a journey into setting this movement up with non-kinematic rigidbodies attached by joints using AddForce and AddTorque (as I've learnt this is the correct way to move non-kinematic rigidbodies). I've tried several different setups - adding Torque to the movement at point A, simulating an 'up' force to the boom to get it to raise/lower, configurable and hinge joints, disabling gravity on the boom - with nothing getting remotely close to how I had it set up previously with the slipping loads.

    I would like to avoid setting this up by attaching the load to the fork via code when it has been picked up, as it feels like the physics system should allow for this type of interaction, but I've run out of ideas to get it working this way. So, I would like to ask for any advice into whether I'm going about this the wrong way or may have missed something that would enable me to get this working correctly.

    Thanks for reading.
     
  2. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    332
    Have to considered using joints?
    https://docs.unity3d.com/Manual/Joints.html

    Joints can be used to attach two rigidbodies in different ways. Probably, the best for you is a FixedJoint. You could develop a wrapper class that creates a joint between the load and the the fork.

    I agree with you that the Friction Force is poorly simulated right now, but take a look to physics material, it may help you
    https://docs.unity3d.com/Manual/class-PhysicMaterial.html
     
  3. rick-phillips

    rick-phillips

    Joined:
    Sep 23, 2012
    Posts:
    4
    Thanks for the advice, Maeslezo.

    I've tried joints for the boom rotation and extension (points A and B on the drawing) with the intention of having three configurable joints to handle the movement. This kind of works but isn't giving me the result I'd expect and is slightly unpredictable and hard to control. This may be due to me not exploring what values do to the simulation so I may need to dig a bit deeper.

    I understand what you're saying about the fixed joint for the load and fork relationship. I wanted to avoid this as I'd assume it would require some code to allow for the forks being tilted forward while in the air, causing the load to fall off realistically. It might be the best way to approach it though.

    edit: I've also played with physic materials too. These seem to be ignored when moving directly through a transform's position/rotation but work great when the rigidbodies are moved correctly.
     
    Last edited: Oct 18, 2018
  4. tasadar

    tasadar

    Joined:
    Nov 23, 2010
    Posts:
    290
    regular constraints are not good for such articulations, check this one:



    bullet has such implementation(featherstone), you can try integrating.
     
  5. rick-phillips

    rick-phillips

    Joined:
    Sep 23, 2012
    Posts:
    4
    Thank you for making me aware of Bullet Physics! It's been a while since I've been able to try getting this to work but I'll have a play with it and see if it's possible.