Search Unity

Lifting object with another object falls through (forklift sim)

Discussion in 'Physics' started by bbjones, Sep 1, 2020.

  1. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    Think of a forklift simulation.

    I have a pallet with rigid body and colliders for the top/bottom and blocks around the edges.

    I have a forklift with colliders on the tines/tongs.

    I drive the forklift, insert the tongs in the available spaces in the pallet, and can lift up/down at least a bit. But, the pallet will always fall through the tongs back to the ground at some point. Usually only after lifting a few centimeters.

    My forklift controls simple move the tines up/down via held keypress. But I get the same behaviour maually changing the Y position in the scene editor.

    If I drive around with the pallet on the tongs it will also fall off fairly quickly.

    I've tried various combinations of rigid body settings, collider placements, moving code between update/fixed update. My timestep is down to 0.01667 which is the suggested value for the vehicle controller I'm using (NWH).

    Any suggestions? I really don't want to auto-lock or parent the pallet to the forklift once engaged since that sort of defeats the purpose of the sim.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,512
    As far as I know, tines must belong to a separate rigidbody attached to the main body via joint. You could then move the tines using the joint methods.
     
  3. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    Thanks, Edy. Got closer with that.

    I was also moving the tines by the gameobject.transform.position, but have changed to use the rigidbody.MovePosition().

    That all seems to have fixed my pallet falling through my tines, but I have new issues as you can imagine.

    My forklift now has 3 rigid bodies: Main body, forklift mast, forklift tongs.
    I'm using configurable joint connecting each - tongs to mast, mast to body.

    When the tongs reach their max height, the mast raises until it reaches its max height.

    Next 3 issues are:
    1) calculations for "new position" param for RB.MovePosition(). I'm currently just moving up the Y which of course isn't respecting the vehicle's actual vertical angle. I believe I need to include offsets for the parent rotations.
    2) when the mast is raised up the tongs move with it. When the mast is lowered the tongs do not move with it. I have the tongs rigid body to IsKinematic since I don't want gravity. With gravity on they fall to the ground on play start. Maybe I'm not connecting the joint properly?
    3) Once I move the tongs up or down, they become detached from the vehicle and I can't move them by running into them. If I don't move them, they move with the vehicle as I drive around.

    I'm new to working with physics and will keep researching, any suggestions on good primer tutorials are appreciated.
     
  4. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    Found a free asset that did it reasonably well not using joints or rigid body on the forks.
    https://assetstore.unity.com/packages/3d/vehicles/controllable-forklift-free-80275

    Instead of changing the fork tine transform.position they used Vector3.MoveTowards().

    Not sure why but that works just as well as using rigid bodies and joints on everything. And is actually even better because my up/down movements are back to being local so I don't have to worry about any rotations or angles.

    So far it is working just fine lifting/moving pallets around.
     
    Edy likes this.
  5. bbjones

    bbjones

    Joined:
    Feb 1, 2016
    Posts:
    85
    Not sure what you're asking, or if you're just selling forklifts :)

    But I'm using NWH Vehicle Physics 2 as the base vehicle mover (for now at least) and building up my own libraries for heavy equipment stuff, forklifts, excavators, cranes, tow trucks etc, trying to get it all working with proper physics so you can interact with objects in the world... and destroy stuff.

    https://assetstore.unity.com/packages/tools/physics/nwh-vehicle-physics-2-166252

    Latest challenge is trying to get the forklift mast tilt to work properly using a hinge joint.