Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Creating custom Joints? Simulating mechanical servos?

Discussion in 'Physics' started by CloudyVR, May 21, 2023.

  1. CloudyVR


    Mar 26, 2017
    Hi I am using Unity 2019.4 and need a rigid joint for a ML robot.


    I am currently researching robotics controls and have spent the past few weeks trying to figure out how to use Unity joint system to no avail, it seems every time I try creating a joint system it becomes springy and the result is very unstable.

    I have tried using Articulation body in 2022 version of Unity but is not a option for my target editor. Also I found Articulation body more difficult to work with, impossible to reset to initial rotations, can't move the rigidbody directly, etc..

    In Unity 2019 I have tried configurable joint, hinge joint or character joint but the result is always springy non-rigid joints that seem to wobble, I try to keep the mass distribution even, increasing physics step but the robot's legs always have a noticeable spring. Even after setting force to infinity makes little difference.

    I also tried moving the robot without joints (using only a single rigid body and by moving the transforms) which appeared to move without any spring however the colliders were sliding on the ground so physics were not being calculated properly.

    I am hoping to create a custom joint, similar to articulation body but that can be used in my project for controlling the servos of the robot for locomotion.

    I have read that custom joints are possible, but I have no idea how to implement them. I think my application is simple needing only to rotate around one axis but the rotation should be very rigid. Forces like friction from the feet would need to be included,

    Is it possible to create a robot joint in Unity that acts more like a servo that doesn't spring or fall apart?

    Thank you
    Last edited: May 21, 2023
  2. arkano22


    Sep 20, 2012
    You really, really want to use articulated bodies for this.

    It’s of course possible to write your own joints, at the end of the day they just calculate and apply positional/rotational impulses to the rigidbodies so that they meet specific constraints. However by the time you figure out the math for the general case you’d have reinvented the built-in Configurable Joint, and figured out that maximal-coordinate based joints (that remove DOFs from an otherwise free to move body) tend to be springy and unstable in all engines unless you use a really small timestep. The solution to this is using a reduced-coordinates approach, like Featherstone’s articulated body algorithm, which is what Unity’s articulated bodies implement.

    So save yourself the pain and just use articulations.

    (as a side note, moving a rigidbody by setting its transform values completely sidesteps velocity calculations such as friction -as a transform directly sets position/rotation-, so never use transforms when dealing with rigidbodies. Use rigidbody.MovePosition/Rotation instead)
    Last edited: May 22, 2023
  3. tjmaul


    Aug 29, 2018
    Also, you can reset joint rotations and velocities by setting their jointVelocities and jointPosition properties in their respective reduced coordinates. And you can also teleport the whole articulation tree by using TeleportRoot on the root articulation body. It just doesn’t work in the editor using the transform gizmos.