Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 TyGuy223 · Mar 09, 2021 at 02:59 AM · physicsfixedupdatesimulation

How to make physics truly update in real time

I'm using Unity for robotics simulation, and would like to have Unity update its physics at a fixed real time rate. I know that fixedUpdate() is called at a fixed rate according to game time, but in reality it's frequency varies wildly with framerate. I believe I understand why this is fine for games, but if I want to receive a real time sensor stream from Unity this causes issues.

As an example, when I set fixed timestep to 0.001 and record the delta time in real life between each fixed update, I get this alt text

What I'd like to see is a tighter grouping of delta time around 0.001 like alt text

Is there a way to achieve this with the default Unity physics engine PhysX? I should say that I did not record these values directly from Unity, but through a websocket connection using ROS#.

This issue has been brought up and described in better detail here. They do bring up the possible solution of setting Physics.autoSimulation = false and running Physics.Simulate() manually, but I have not managed to get this to work.

Any advice in solving this would be appreciated. If necessary, I'm okay with using a different physics engine.

gazebo-1000hz-deltatime.png (26.6 kB)
unity-1000hz-deltatime.png (37.8 kB)
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 Captain_Pineapple · Mar 09, 2021 at 02:52 PM

Well okay short answer: What you are looking for is an actual "real-time" simulation. Unity can not do this as far as i am aware.


To dive a bit further in: 0.001seconds is a really really small stepsize. I doubt that values this small are encouraged by Unity. You could perhaps get a bit further in this direction if you scrap unitys default update cycle and create your own from scratch. There are functions to change the updatecycle but i have never reall dug into this. (you can for example remove Update and exchange that by something else. This way you could remove unnecessary steps) Either way the result you show makes sense and your desired behaviour will never be reached with default behaviour. Unity will not trigger Updates/Fixed Updates "early" just because time is close. It will always trigger on time or later. Then again i guess you can assume a somewhat "fixed deviation time". This time normally is negligable but somewhat constant no matter how large the fixed step size. However if you stepsize itself is that small you will have issues as the deviation suddenly could be as large as your step itself. And in the end i doubt that you'll be able to change anything about this.


So to sum it up: yes you could perhaps get your desired deviation distribution by manually simulating an thus enableing "early" update execution. However i highly doubt you'll be able to get the deviation magnitude you desire with such a small step size. That beeing said you perhaps should check out other physics simulations (perhaps some that are actually made for real time computation though that sometimes can require extra hard and software since neither Standard Linux or Standard Windows is good at real time computations) This can also include to check if unitys efforts to include the havoc engine has been fruitful yet. (Last time i checked you needed a license though)


Hope this made sense and was helpful. Good luck to you.

Comment
Add comment · 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

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

191 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

Related Questions

How to make an earthquake shake and let any gameobjects with a rigidbody react to the earthquake using physics? 1 Answer

Game starts stuttering over time 0 Answers

Simple colliding objects are updated a frame late. 0 Answers

FixedUpdate vs. Update for instantaneous ForceMode's 1 Answer

OnCollisionEnter inside FixedUpdate? 1 Answer


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