Search Unity

Resolved Time scale question

Discussion in 'ML-Agents' started by AngrySamsquanch, Jan 14, 2021.

  1. AngrySamsquanch

    AngrySamsquanch

    Joined:
    Dec 28, 2014
    Posts:
    24
    I have a rolling ball as an agent which receives a force applied during on action received. I would like to use a ray perception sensor but it rotates with the ball. I've added this sensor as a child and during late update I reset the rotation, which works fine when testing in the editor. However, when I attempt to train it still rotates the sensor somewhat if I have the time scale set to a value above 1.

    Is there a general rule of thumb when it comes to physics simulations and time scale?
     
  2. Luke-Houlihan

    Luke-Houlihan

    Joined:
    Jun 26, 2007
    Posts:
    303
    [Edit] Vincentpierre gives a better explanation below for the time scale.

    You can lock the x,y,z rotation on your ball's rigidbody and just use a physics material to control roll-like-behavior via the friction. Or if you really need the ball to actually roll you can just put a rigidbody on the ray perception sensor, lock it's rotation, and just update it's rigidbody.position in
    FixedUpate()
    to match the ball.
     
    Last edited: Jan 15, 2021
  3. vincentpierre

    vincentpierre

    Joined:
    May 5, 2017
    Posts:
    160
    LateUpdate is on the same cycle as Update. FixedUpdate is on a different cycle. ML-Agents methods are called in the FixedUpdate cycle, so it is not recommended to have some logic of the same Agent be split over FixedUpdate and LateUpdate.
    If you increase the time scale, the ratio of Updates vs FixedUpdates will be changed and this is why you see the rotation more when using a larger timescale.
     
  4. AngrySamsquanch

    AngrySamsquanch

    Joined:
    Dec 28, 2014
    Posts:
    24
    Thanks for the help. FixedUpdate did the trick.