Search Unity

Rigidbody interpolation borks out when object changes direction

Discussion in 'Physics' started by prabab, Oct 16, 2017.

  1. prabab

    prabab

    Joined:
    Apr 10, 2013
    Posts:
    9
    I've come to this really strange issue. I'm working on a rather simple custom FPS player controller based on Rigidbody. The player rotates with mouse look, which happens to change object's LocalEulerAngles.

    What I've noticed, that as soon as I enable interpolation, weirdly enough every time camera (object) rotates, the object slows down to 0 and won't start gaining speed unless I stop turning around.

    This doesn't happen with interpolation disabled (however, movement looks somewhat jerky without interpolation).

    Both walking (addForce) and mouse look are triggered on FixedUpdate().

    Any ideas?
     
  2. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    You should never do things like mouse look in FixedUpdate.

    Even if you get the problem under control, you'll still have the problem of your input getting processed at a lower framerate than the game. And eventually that will become noticeable anyway.

    All player input should be processed in Update. Otherwise you will get things like missed clicks and key-presses as well.
     
  3. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    Maybe your movement logic reads position and/or rotation from the Transform? If so, those values might differ from the actual physics-defined pose due to interpolation. Use Rigidbody.position and Rigidbody.rotation instead.

    I don't think this issue has to do with the input being processed in FixedUpdate. Discrete events (mouse down, key down...) must be processed in Update, but continuous events (is key pressed, mouse position, input axis) may be processed in FixedUpdate instead.

    A typical game runs at the physics rate regardless of the frame rate. The Update cycle applies the visual interpolation. Decisions taken in Update won't have effect until the next FixedUpdate is processed. In my case, I process almost all the input in FixedUpdate (which is also useful for recording input and playing replays), with the Update method being used for detecting the discrete input events so they are processed in the next FixedUpdate.
     
  4. AviSci

    AviSci

    Joined:
    Aug 17, 2017
    Posts:
    4
    That's been happening on my project with the new release. Using rigidbody.moveposition and the object immediately goes full stop when changing direction before moving again. Rolling back to 2017.1.2 fixed it...
     
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,508
    Please fill a bug report. Looks like there are important physics issues with 2017.2:
    http://forum.unity.com/threads/2017-2-physics-broken.499886/
     
  6. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Id recommend you do as well Edy, your a well respected asset store developer with a solely physics based asset, so reports from you will likely go a long way.
     
    devotid likes this.