Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by 82MiddleMan · Nov 01, 2021 at 10:48 PM · rigidbodyvrfixedupdate

VR: Using rigidbody for movement, and getting fixed time in sync with frame rate

I have a rigidbody that my VR camera rig is attached to. To move the player I add force to the rigidbody. For this to be smooth I have to set FixedDeltaTime to 1 / VR refresh rate. (I'm controlling it in FixedUpdate and using Interpolate on the rigidbody)


When I do just this it becomes silk smooth most of the time, but every 3-6 minutes it starts to judder badly for about 10 seconds, then goes back to being smooth again. The scene is quite basic, and I can see from the oculus debug tool, and unity profiler that this is not performance related. It seems to be a timing issue with fixed time. By debugging I can see that when it judders, it is doing 2 updates, then 2 fixedUpdates repeatedly (and 1 of each when smooth).


After experimenting I tried setting fixedDeltaTime to deltaTime at the beginning of an Update(). This seems to sync them up. I don't get the judder and with Interpolate set to Extrapolate on the rigidbody, it's nice and smooth.


This doesn't feel like the best solution though. I will be adding multi player soon. Will my fixed time being variable from frame to frame cause issues down the line?


I suspect that the problem here might be because the refresh rate of the headset is 90. 1 / 90 is 0.0111111111111111. But unity rounds this to 8 decimal places (0.01111111). This must be a common problem but I can't find much about it online.


Is there a better way I can sync fixedDeltaTime to always be in time with the frame rate, but with it still being constant?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by rh_galaxy · Nov 01, 2021 at 11:32 PM

In my VR-game (supports Quest, Rift, and SteamVR) i have Fixed Timestep set to 0.01 (100Hz), and SteamVR does what you do by default, having a variable fixed update, which even sounds wrong.

You have to do:

 SteamVR.settings.lockPhysicsUpdateRateToRenderFrequency = false;

I'm not having multiplayer (yet), but I do have a replay-recording and playing functionality which demand a fixed update at a predefined value.

The index headset can run up to 144Hz, the Quest as low as 60 but also 72Hz and 80, Rift 90, Rift S 80. It's not practical to try and sync this, leave the framerate alone and set a fixed fixed update.

You must combat the choppynes in some other way.

My code in my CameraController follows at an offset a ship (player) with a Rigidbody2D attached, and it works very smooth, no sign of the problem you are experience. But I don't know exactly why it works, maybe Interpolate and LateUpdate does the trick(?).

 GameObject oPlayer; //has RigidBody2D attached to it
 private Vector3 vCamOffset;
 private Vector3 vMapSize;
 internal static Vector3 vCamPos = new Vector3(0, 0, -4.5f);
 
 public void InitForGame(GameLevel i_oMap, GameObject i_oPlayer)
 {
     oPlayer = i_oPlayer;
     oMap = i_oMap;
     vCamPos = new Vector3(0, 0, -10.0f); //set it away from the player,
     // transform.position will then be set first Update
     vCamOffset = new Vector3(0, 0.3f, -1.90f);
     vMapSize = oMap.GetMapSize();
 }
 
 void LateUpdate()
 {
     Vector3 v = oPlayer.transform.position;
     float fLeftLimit = -(vMapSize.x / 20.0f) + 0.5f;
     float fRightLimit = (vMapSize.x / 20.0f) - 0.5f;
     if (v.x < fLeftLimit) v.x = fLeftLimit;
     if (v.x > fRightLimit) v.x = fRightLimit;
     float fTopLimit = (vMapSize.y / 20.0f) - 0.3f;
     float fBottomLimit = -(vMapSize.y / 20.0f) + 0.5f;
     if (v.y < fBottomLimit) v.y = fBottomLimit;
     if (v.y > fTopLimit) v.y = fTopLimit;
     v += vCamOffset; //add this after limiting
     
     transform.position = v; //camera holder
     vCamPos = v;
 }

alt text


rigidbody2d-for-player.jpg (22.9 kB)
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 82MiddleMan · Nov 02, 2021 at 04:59 PM 0
Share

Thanks for the response. I've done some more experimenting and sure enough, running fixed time at 100Hz with my 90Hz headset is smooth enough.

However, running fixed time at 90Hz still has long moments of stuttering. Even on 91Hz it has the occasional stuttered frame. So I'm wondering if 100Hz is enough. Will that have the same problem on headsets that use 120Hz or 144Hz? I could go up to 150Hz or something, but will that be too fast for multiplayer, and will it be fine on quest?

avatar image rh_galaxy 82MiddleMan · Nov 02, 2021 at 07:26 PM 0
Share

I'm not sure if there is a need to always have fixed timestep above framerate... I don't think so but I haven't actually tried it myself. Had one user trying it on the Index with 144Hz with no complaints, but maybe he didn't notice...

avatar image 82MiddleMan rh_galaxy · Nov 03, 2021 at 12:21 AM 0
Share

How do you make the rigidbody move. Do you addforce?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

221 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ConfigurableJoint Target Position/Rotation Issues? 1 Answer

Is time-based update necessary in FixedUpdate? 1 Answer

How do I fix jitter? 1 Answer

Why does the object rotate around the hands with the "kinematic" parameter?,Why does the object move in the hands with the "kinematic" parameter? 0 Answers

How do i stop XR rig from moving rigidbodies 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges