Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

SteamVR rigidbody hands lagging behind

Discussion in 'AR/VR (XR) Discussion' started by ArthurHoeke, Apr 3, 2020.

  1. ArthurHoeke

    ArthurHoeke

    Joined:
    Nov 27, 2014
    Posts:
    12
    I'm developing a VR game in which the player sits inside of a spaceship and can interact with various object to control the ship. I've created a throttle which controls the velocity of the ship using addforce and making the player object a child of the cockpit. The player does properly follow the cockpit's rigidbody movement, though when the player isn't holding an object with their hands they lagg / jitter real badly behind.

    https://i.gyazo.com/730a2b918f6e519ddc6134743f629c78.gif


    Code (CSharp):
    1.     private void Update()
    2.         {
    3.             speed = throttle.GetComponent<Valve.VR.InteractionSystem.LinearMapping>().value;
    4.         }
    5.  
    6.         private void FixedUpdate()
    7.         {
    8.             GetComponent<Rigidbody>().AddForce(-transform.up * (speed * 20), ForceMode.Impulse);
    9.         }
    How would I go about fixing this?
     
  2. ArthurHoeke

    ArthurHoeke

    Joined:
    Nov 27, 2014
    Posts:
    12
  3. CGPepper

    CGPepper

    Joined:
    Jan 28, 2013
    Posts:
    151
    Interpolation will often cause gitter, but it's probably not happening here.
    Are you using rigidbody hands inside a rigidbody/translating spaceship? You can't have a rigidbody as a child of a moving object
     
  4. ArthurHoeke

    ArthurHoeke

    Joined:
    Nov 27, 2014
    Posts:
    12
    Yes the hands to have their own rigidbody. If that's not the right way of doing it how would I go about keeping the player's hands following their body / inside the spaceship?

    I suppose I'd have to make the player not a child from the spaceship anymore and maybe in an update function keep it centered in the spaceship seat by setting the transform? Might look laggy aswell / bad for performance.
     
  5. CGPepper

    CGPepper

    Joined:
    Jan 28, 2013
    Posts:
    151
    the only way that i found of not having nested rigidbodies,
    is to create an invisible rigidbody + collider outside of the parent, and move it to correct position on each frame

    LefHandCollider is an invisible object that moves to the position of LeftHandAnchor on FixedUpdate.
    upload_2020-4-10_16-52-45.png

    In my case, i only need 1 big collider, but if you have a whole bunch connected to each finger, it can take some work
     
  6. ArthurHoeke

    ArthurHoeke

    Joined:
    Nov 27, 2014
    Posts:
    12
    I've tried a couple things now, when removing all rigidbodies and simply moving the position using transform forward I still had the same lagg in the hands. Though when setting the handcollider's rigidbody to interpolate they were moving smoothly along.

    Sadly I do need to use a rigidbody for the spaceship though, since I want to have it react properly to collisions. I've tried putting the player and spaceship in a parent object which controls all movement via it's rigidbody, but that gives the same results. I've also experimented with fixedjoints, but that doesn't work properly with the addforce of the rigidbody.
     
  7. Monkis

    Monkis

    Joined:
    Sep 29, 2016
    Posts:
    4
    Hi Arthur. Have you made any headway on this issue? I am working on a racing game and have the same issue. I have turned off gravity on the hand collider rigid bodies as suggested here https://forum.unity.com/threads/steamvr-handcolliderleft-right-lags-behind-hand-movement.832168/ however it only keeps them calmer for a bit longer and they do start to wander backwards, then go crazy after my cars rigidbody velocity magnitude goes over 30. I also tried altering the HandCollider.cs code to force a position move to match the hand position but to no avail.
     
  8. JaviCoder

    JaviCoder

    Joined:
    Sep 7, 2017
    Posts:
    3
    hello, i was having the same issue, hands shaking a lot.

    i ended comenting the line 200 of file "HandPhysics .cs": hand.mainRenderModel.transform.position = offsetPosition;

    this makes some weird offset between the hand colliders and the model itself.
     
  9. kyliant

    kyliant

    Joined:
    Aug 31, 2014
    Posts:
    1
    Still no solution I take it?
     
  10. hockenmaier

    hockenmaier

    Joined:
    May 11, 2016
    Posts:
    11
    Go into each "Hand" object under the "SteamVRObjects" object and disable the "Hand Physics" script on both. Your hands will go through things, but you will still be able to interact/grab objects etc. That script doesn't seem compatible with fast player motion from a performance perspective.

    If anyone finds a way to optimize that script instead of just disabling it I would be interested!
     
  11. CVLocke

    CVLocke

    Joined:
    Mar 15, 2022
    Posts:
    1
    I tried to change that line to "hand.mainRenderModel.transform.position = Vector3.Lerp(hand.mainRenderModel.transform.position, offsetPosition, Time.deltaTime * smoothness);"(smoothness is my public float value) and it worked perfectly well!
     
    JaviCoder likes this.
  12. Paul33993

    Paul33993

    Joined:
    Jan 4, 2015
    Posts:
    27
    I'm making a game that a believe has a similar concept.

    For things not to be completely broken when moving at high speeds, I must do my transform updates with void LateUpdate().

    LateUpdate occurs after physics calculations have been performed and allows my transform updates to be placed in the proper position.
     
  13. rabblerousy

    rabblerousy

    Joined:
    Mar 9, 2020
    Posts:
    4
    THIS WORKED FOR ME!! Thanks! :)
     
    hockenmaier likes this.