Search Unity

Bug Jittery movement of Rigidbody attached to camera

Discussion in 'AR' started by edwon, Jan 26, 2021.

  1. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    I've tried everything I can think of, but I still get a horrible jitter effect when setting MovePosition of a Rigidbody to stay in front of the AR camera.

    I've tried setting it to kinematic and also using Update vs. FixedUpdate, no matter what it still looks terrible (see video to see the jitters of the white ball as it tries to stay in front of the camera)



    using the latest Unity and ARFoundation and ARKit plugins (but I've seen this issue even back when I was developing with VR in Unity, seems to be some kind of timing difference between XR provider updates and render updates? I have no idea)
     
  2. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    323
    Try changing the rigid bodys interpolation setting.

    Try all three settings
     
  3. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,139
    Try using LateUpdate(), this way you'll update the position of your pointer AFTER the camera position update.
     
  4. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    I ended up having to set Interpolation to interpolate, and using LateUpdate
    and it only looks smooth if isKinematic is on, it still looks jittery if using non-kinematic though (combined with rigidbody.MovePosition) any thoughts on how to fix this case?
     
  5. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    323
    Can you toggle isKinimatic only when the object is being moved/dragged by the camera, then toggle back? Or is that not functional for your setup?
     
  6. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    yeah I can, I guess that's fine
     
  7. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    323
    Haha, yeah i would say i feel as enthusiastic about the work around as you do.

    Im not sure what's going on there w the jitter. The other day i spent hours on a similar problem where the rigid body had jitter when moved only if the camera was also moving. Position was based off a camera raycast like i assume yours is.

    I did everything possible as far as repositioning code to Update, FixedUpdate, LateUpdate, cinemachine update settings, non cinemachine at all.

    In the end interpolation was the problem. And in my case interpolation = none was the fix (not quite the same as you).

    This was not an AR app.

    However i also have an AR app where i move and drag rigid bodys while moving camera and everything works just fine. Never had jitter in the first place. Id have to look but i think all the rigid bodys are default settings, which i think is interpolation none, and is kinimatic false.

    Sooooo. I guess im not helping by saying all that but i dont know its almost like we have had the same problem, but the answer was the opposite for us
     
  8. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,819
    tree_arb likes this.
  9. Leohd

    Leohd

    Joined:
    Feb 7, 2017
    Posts:
    32
    If you move an object using FixedUpdate(), use "rb.velocity = x" or rb.AddForce().

    rb.MovePosition() is an instant teleportation, so it causes jitter problems when used in conjunction with FixedUpdate().