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

ML Crawler SetJointStrength

Discussion in 'ML-Agents' started by TrashestCoder, Apr 25, 2022.

  1. TrashestCoder

    TrashestCoder

    Joined:
    Jan 27, 2017
    Posts:
    14
    Could someone assist me with the SetJointStrength method in Crawler? I'm having trouble figuring out the rawVal formula and where it came from. Could someone please point me in the right direction?

    Code (CSharp):
    1. public void SetJointStrength(float strength)
    2.         {
    3.             var rawVal = (strength + 1f) * 0.5f * thisJdController.maxJointForceLimit;
    4.             var jd = new JointDrive
    5.             {
    6.                 positionSpring = thisJdController.maxJointSpring,
    7.                 positionDamper = thisJdController.jointDampen,
    8.                 maximumForce = rawVal
    9.             };
    10.             joint.slerpDrive = jd;
    11.             currentStrength = jd.maximumForce;
    12.         }
     
  2. WaxyMcRivers

    WaxyMcRivers

    Joined:
    May 9, 2016
    Posts:
    59
    Interested in this as well
     
  3. lfritz

    lfritz

    Joined:
    Oct 12, 2021
    Posts:
    3
    It's just a normalization of the action values from the range [-1,1] onto [0,1].
    ([-1,1] + 1) / 2 ==> [0,1]

    It is then multiplied by the Max Joint Force Limit, which is a parameter you can set in the Crawler prefab.
    Basically the float number multiplied by it is the amount/percentage of the maximum force. So rawVal gives you the predicted force for this joint.
     
    TrashestCoder and WaxyMcRivers like this.
  4. TrashestCoder

    TrashestCoder

    Joined:
    Jan 27, 2017
    Posts:
    14
    Thanks, everything makes sense now :)