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.

Question Moving and rotating Agents in official ML-Agents examples (transform.Rotate VS. rb.ApplyTorque)

Discussion in 'ML-Agents' started by afhorne, Mar 2, 2023.

  1. afhorne

    afhorne

    Joined:
    May 3, 2021
    Posts:
    5
    I saw that most of the official ML-Agents examples move and rotate their agents in this way:

    Code (CSharp):
    1. rb.AddForce(dirToGo * moveSpeed, ForceMode.VelocityChange);
    2. transform.Rotate(rotateDir, Time.fixedDeltaTime * rotSpeed);
    (See, for example, here: https://github.com/Unity-Technologi...ples/DungeonEscape/Scripts/PushAgentEscape.cs)

    I have two questions, that maybe someone can answer for me:

    1. Why
    transform.Rotate()
    instead of
    rb.ApplyTorque()
    ? I thought that for Rigidbodies that are not kinematic, it is not advised to use
    transform.Rotate()
    ? (https://docs.unity3d.com/Manual/RigidbodiesOverview.html).

    2. And why
    ForceMode.VelocityChange
    instead of
    ForceMode.Force
    (the default)? Shouldn't ForceMode.Force make for smoother movement, especially since ForceMode.VelocityChange doesn't even depend on the simulation step length? (https://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html)

    Thanks for your help! :)