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
0
Question by AzanticGames · Jul 22, 2020 at 12:06 PM · physicsfixedupdatetimescaledeltatime

Setting fixeddeltatime depending on TimeScale makes physics behave weirdly

I ran into a Physics issue when setting the fixedeltatime timestep at runtime according to the current Time.TimeScale. I frequently change the TimeSclae in my project at runtime in order to create slowmotion and bullet time effects. In order to also have smoothly working Physics and other features depending on the fixeddeltatime, I also set Time.fixedDeltaTime accordingly (Time.fixedDeltaTime = 0.02f x timescale). While this indeed gives me smooth behaviour even during the slow motion I ran into related issue that I cannot seem to solve: Applying a force to a rigidbody does not seem to work at all times anymore. This also occures if the TimeScale is 1 and thus fixeddeltatime = 0.02f.

I tried to debug the problem and it seems like it is related to setting fixeddeltatime at runtime, regardless of the new fixeddeltatime value. This problem even occures when time fixeddeltatime is only set once at the start to the default value of 0.02f.

In short: setting fixeddeltatime manually (even setting it once at the start of the game to the same default value of 0.02f as it already is makes physics work in a weird way, which leads to forces sometimes not being applied properly)

Does anybody have an idea how to resolve this issue? If need I can provide video material and code examples

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
Best Answer

Answer by Edy · Jul 22, 2020 at 04:40 PM

Don't change fixedDeltaTime. Doing so will change the physics behavior in unpredictable ways. Change Time.timeScale alone to get physically coherent behavior regardless how often timeScale is changed, or its value.

You can get visually smooth motion at any time scale by enabling Interpolation in the rigidbody.

Comment
Add comment · Show 3 · 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 AzanticGames · Jul 22, 2020 at 06:22 PM 0
Share

Hm okay. As far as I had known it is recommended to do that but I might be wrong. How would you go about other things that depend on the fixeddeltatime? For example Cinemachine updating, other code that has to be run in fixedupdate etc?

avatar image Edy AzanticGames · Jul 22, 2020 at 06:45 PM 0
Share

They should either be updated in Update using Time.deltaTime, or implement their own interpolation in Update.

Cameras should be updated in Update or LateUpdate to adapt to the visual frame rate, not the physics frame rate. If the systems shouldn't slow down with the time scale (i.e. camera motion should be the same speed regardless time scale) then they should update in Update and use Time.unscaledDeltaTime.

If the system is updated in FixedUpdate but it requires smoothly visuals then they should interpolate their pose in Update, then apply the interpolated pose to the visual object. For example, in this video:

https://www.youtube.com/watch?v=KZmEEynnG6$$anonymous$$

The second part is slow motion. Wheel rotation is updated in FixedUpdate, but the visual wheel mesh is rotated in Update using values interpolated from the last two FixedUpdate cycles.

avatar image AzanticGames Edy · Jul 22, 2020 at 11:38 PM 1
Share

Alright I looked into it and it seems your workaround seems to work really well. Thank for taking the time to help me out!

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

215 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

Related Questions

Problem with Fixed Timestep 0 Answers

Force physics collision calculation (forced fixed update) 0 Answers

Physics calculations vs TimeScale vs FixedDeltaTime 1 Answer

Is it okay to use ForceMode.VelocityChange in Update()? 1 Answer

How to set a fixed timestep for Particle System? 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