Excavator with Rigidbody and childs which should be moved with physics

Hello all,

i am struggling now for quite a while. I am trying to programm an excavator simulation for my little son, who loves that stuff. Now i am struggling with some physics problems i cannot find a good solution for.

To the Gameobject:

MainGameObject(Excavator)
|_ Rigidbody attached with gravity on, dicsrete set
|_Body(which should rotate arount 360 degrees)
… keep it that simple because its enough to describe the problem

So now the scenerio. I am picking up with the bucket some smaller objects also with an rigidbody attached to it. When i am now rotating the Excavator with its tracks and use physics like rigidbody.velocity, the objects stay clean and without jiter in the bucket and the reactions to frictions and so on are accurate.

But you may guess it, when i keep the tracks at position and just want to rotate the body, i need to use translate or rotate stuff. Then the physics go mad and my stuff in the buckets falls out and so on.

I already tried to tie up the lower part with the tracks with body with two seperate rigidbodies, but neither a hingejoint or fixedjoint were even able to keep the body stable in place, and if the body hits another rigidbody it goes really mad.

So i know my problem, but i have no clue how to solve it.

Is there maybe a way to use also constrainst to fix joints better? Additional Rigidbodies as kinematic did also no good.

Has someone experienced something similar? Because moving the arms and so works fine, but with broken physics, which even my 5 years son complains about :slight_smile:

Hope someone can give me an idea! Thanks.

Matthias

I’ve rigged excavators by resembling their hierarchical layout, like this:

/*
Main GameObject
|  > contains main Rigidbody
|_ Colliders for the main rigidbody
|_ Body GameObject (which should rotate around 360 degrees)
    > contains body Rigidbody
    > contains joint to attach this body to the main Rigidbody
    |_ Colliders for the body
    |_ Boom GameObject
        > contains boom Rigidbody
        > contains joint to attach the boom to the body Rigidbody
        |_ Colliders for the Boom
        |_ arm etc.
*/

All rigidbodies are non-kinematic and use gravity.

Main issue with joint stability is the mass ratio. If the connected masses are similar (1:1) then you’ll have a pretty solid and stable joint. Rule of thumb is the order of magnitude of the masses. If the ratio between masses is greater than 1:10 then you may start seeing instabilities. Higher ratios may require increasing the physics frequency to make them stable. Default frequency is 50 Hz (Time > Fixed DeltaTime = 0.02). If using large mass ratios is a must, then 100 Hz might be enough (Time > Fixed DeltaTime = 0.01).

As for controlling the rigidbodies, you should never use rigidbody.velocity or translate / rotate methods. Those may well define commands that directly violate the joint constraints, so physics go mad. Always use either Rigidbody.AddForce (it has an option to impose a velocity change), or the methods and properties exposed by the joints. These methods allow the physics to solve collisions and joint constraints properly. Translate / rotate methods are ok only in specific sporadic situations, such as teleporting the excavator back to the respawn point.

As for controlling the articulations, the method that works best to me is to use a CustomizableJoint with all constraints set to “Locked” except the one that should move, which would set as “Free”. Then use the Drive options of that constraint for controlling it like this:

  • Set “Position Spring” and “Position Damper” to absurdly large values (i.e. 3e+38, 3e+10). This prevents wobbling and keeps the “Free” element fixed in the position given by “Target Position” or “Target Rotation”, depending of the type of free constraint (linear or angular).
  • Modify “Target Position” or “Target Rotation” to the value you want it to go. This will instantly move the element to that value and cause a counter-force in the body it’s attached to (as in reality). You should modify these smoothly within FixedUpdate like “position = position + motionRate * Time.DeltaTime”.

Hope this helps!

Wow thanks a lot for the hints! I will try them out asap!

Just want zo tell, this solves indeed my Problem. I played a bit, and the ganechange was the spring and damper values set to max. No i can easyly use from the configurable joint tje target rotation to set easyl things i like to rotate. And the best, up to now physics seems to run correct!

Thanks for the great answer!

1 Like

Happy to help! :slight_smile: