0
\$\begingroup\$

In my game, the Player can pick up an object (which gets parented to the first-person camera), or the player can push an object (which is parented to the player, but not their first-person camera). Both mechanics use very similar implementations in regards to moving the objects, yet I get a pretty severe amount of 'perceived' jitter from Pushing -- the object, as far as I can tell, isn't actually jittering.

(Side note - wasn't sure where to upload footage so I used mega which can be used merely to view the footage)

Footage of the push, with visible jitter

Footage of the lift for comparison

Footage of the push but parented to the first-person camera

Footage of push frame-by-frame from the side at 0.50 timescale

Footage of the lift frame-by-frame from the side at 0.50 timescale

The object is moved in FixedUpdate and the camera is moved in LateUpdate. You can see pretty clearly that in the side view, the camera moves after the object. Since the object is parented to the camera on Lift, it moves with it and no change is perceived. However on Push it doesn't move and thus appears to jitter.

I'm not sure how to fix this. I have tried:

  • Enabling interpolation on the rigidbody,
  • Disabling gravity on the rb / lifting off the ground (e.g., not caused by collision with the floor),
  • Not parenting the object to the player at all (object is still perceived to jitter because the camera moves in LateUpdate out of sync with the object)
  • Parenting the object to the camera (but this is highly unintended since they're meant to only be pushing; causes all sorts of issues with rotation etc - but the jitter does stop as is visible in the third link),
  • The following code in LateUpdate to sort of nudge it forwards -
    protected void CheckCameraPosition()
    {
        if (m_LastCameraPosition == Vector3.zero)
            return;

        Vector3 newPosition = m_FPCamera.Transform.position;
        if (newPosition == m_LastCameraPosition)
            return;

        Vector3 newOffset = newPosition - m_LastCameraPosition;
        newOffset.y = 0f;
        Transform.position += newOffset;
    }

But the object still jitters and were I to seriously consider the above code I'd be worried about race conditions since the camera movement is executed in LateUpdate as well.

\$\endgroup\$
  • 1
    \$\begingroup\$ Do you move your rigidbody by its transform at any time? This silently disables interpolation for the frame, even if you have it enabled. \$\endgroup\$ – DMGregory Mar 27 '20 at 2:21
  • \$\begingroup\$ I have! Thanks for the tip. I'll try rigidbody.MovePosition next and see if it solves it. \$\endgroup\$ – Visulth Mar 27 '20 at 5:03
  • \$\begingroup\$ is rb isKinematic true or false when you moving it? \$\endgroup\$ – formatc2013 Mar 27 '20 at 8:03
  • \$\begingroup\$ @formatc2013 isKinematic is false while moving during both lifting and pushing \$\endgroup\$ – Visulth Mar 27 '20 at 16:01
  • \$\begingroup\$ @DMGregory using rb.MovePosition + interpolation completely remove jitter if I set isKinematic = true, which is unfortunate because it would prevent any physics interactions while pushing (e.g. could push the chair through a wall) so I would likely need to create a physics-type simulation/detection for collisions if I continue with that solution. Putting CheckCameraPosition() in Update seems to eliminate a substantial amount of jitter (but not nearly as well as being parented to the camera or kinematic interpolation). I'm also looking into position constraints of the camera transform \$\endgroup\$ – Visulth Mar 27 '20 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.