Search Unity

Stuttering during rotation in VR. Proper method for player turning/rotation in VR?

Discussion in 'General Discussion' started by JamesWjRose, Jul 27, 2020.

  1. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    I am making a hover race game in VR, however I am having an issue. I found this set of videos from Unity about a hover racer and used it. It adds a force to the RigidBody to turn and to move. I get the value of this, however the thing is when the vehicle turns there is a bit of stuttering to the view.

    When I am just standing there and move my head back and forth, there is no stutter. It's when the rotation code, seen below, runs that I get this annoying stutter. This only occurs in VR. I created a testbed scene with a new camera and only this code (as well as the necessary components to show the scene in VR) to insure that it's not some other influence.

    So, before I started trying other turning mechanisms I thought I should ask if there is a standard for movement in VR. Since these are cars obviously I cannot use teleportation, I need continuous moment. Thoughts?

    Tried this in Update, FixedUpdate and LateUpdate. Issue persists in all.

    This happens on all version in the 2019 series as well as the current release of 2020

    EDIT: Here is the camera setup: https://imgur.com/a/XLfBMiB

    Code (CSharp):
    1. float rotationTorque = (playerInput.rudder * rotationSpeed) - rigidBody.angularVelocity.y;
    2.  
    3. rigidBody.AddRelativeTorque(0f, rotationTorque, 0f, ForceMode.VelocityChange);
    4.  
    5. float sidewaysSpeed = Vector3.Dot(rigidBody.velocity, transform.right);
    6.  
    7. Vector3 sideFriction = -transform.right * (sidewaysSpeed / Time.fixedDeltaTime);
    8.  
    9. rigidBody.AddForce(sideFriction, ForceMode.Acceleration);
     
    Last edited: Jul 27, 2020
  2. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    Probably in the camera code. Put the physics in FixedUpdate and the camera tracking code in LateUpdate may help out the stuttering problem.
     
  3. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    Thanks, but the ONLY code for turning the camera parent is stated above. That code is in the FixedUpdate of the parent ; "XR Rig Follow" See this image for details on the XR rig: https://imgur.com/a/XLfBMiB

    I made this simple scene to minimize outsize influence. So... what am I missing?

    Thanks kindly for taking the time. Have a great week
     
  4. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    I only ever get stuttering when I used physics and my camera manipulation was not in LateUpdate..just sayin'. Take it for what it is worth.
     
    JamesWjRose likes this.
  5. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    you need to set the physics timing of your project to match the VR headset screen frequency or exceed it, since the fixed update is not tied to framerate but to a fixed time lapse.
    try with 0.012 in the Time setting on the project properties.
     
    angrypenguin likes this.
  6. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    I will check that out. Thank you very much.
     
  7. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    to fine tune it, use this formula:
    Fixed Time Step = 1 / headset frequency
    For the Quest, it's 72hz
    for the oculus Rift S, it's 90hz
    For every headset it can be different.
    You can check the screen vertical frequency using this.
    Also, you can set the fixed time step by script using Time.fixedDeltaTime = 1f/frequency
     
    robmt, angrypenguin and JamesWjRose like this.
  8. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    You may also be able to use interpolation on the Rigidbody, but I don't know if that'll introduce other issues.
     
  9. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    Camera tracking code should be done in LateUpdate.

    Physics run at different framerate and that framerate cane be LOWER than screen refresh rate.
    By default, by the way, it is running at 50 fps, and compared to 90, 80 or 75Hz refresh rate of VR, yeah, it is going to stutter. So either don't use physics code for camera, or configure physics framerate to match that of your headset.
     
    angrypenguin and JamesWjRose like this.
  10. JamesWjRose

    JamesWjRose

    Joined:
    Apr 13, 2017
    Posts:
    687
    Ah, ok. I think I get your point. This is an odd situation when dealing with racing games. I will have to think about the entire process. Thank you for the info