Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 MacMC · Oct 11, 2018 at 02:49 AM · framerateindependentdelta

any way to *not* use deltaTime when framerate slows?

Let me explain. I'm looking for what is essentially a 'hybrid' timestep. I'm making a bullet hell game which requires very little incongruencies with bullet patterns and speed. As a result, when the framerate slows down past a certain target framerate (say, 60 fps) I would prefer my systems run without taking delta time into account. So calculations would be taken step by step and the simulation would run more slowly, which is exactly what I want. On the other hand, once it's past the target framerate, I would like it it to maintain the delta, so it just moves more smoothly without speeding up.

Any suggestions for this, or solutions like it?

Comment
Add comment · Show 1
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 NoDumbQuestion · Oct 11, 2018 at 04:44 AM 0
Share

http://www.kinematicsoup.com/news/2016/8/9/rrypp5tkubynjwxhxjzd42s3o034o8

TLDR: use fixed time for physics simulation. delta time for camera/render stuff

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Oct 11, 2018 at 08:09 AM

Well, there's an easy fix for your hybird solution ^^ just clamp deltaTime properly. That means it should never grow beyond "1 / 60" (-> 0.016666).


 float dtFixed = Math.Min(Time.deltaTime, 1f/60f);

Note that this only fixes things you control and where you use dtFixed instead of Time.deltaTime. This could be implemented in a seperate static class

 public static class MyTime
 {
     public static float maxDT = 1f/60f;
     public static float TargetFrameRate
     {
         get { return 1f / maxDT}
         set { maxDT = 1f / value;}
     }
     public static float deltaTime
     {
         get
         {
             if (Time.deltaTime > maxDT)
                 return maxDT;
             return Time.deltaTime;
         }
     }
 }

Now you can simply use MyTime.deltaTime instead of Time.deltaTime. You can change the target framerate be either setting MyTime.maxDT or MyTime.TargetFrameRate. This essentially returns a fix dt value (maxDT) when the framerate drops below your target framerate.


Note as i said above this only fixes things which will use your deltaTime. For example physics runs on a fixed framerate and isn't affected by deltaTime at all. Particle systems and the animation system runs with Unity's internal deltaTime value. Those are not affected by this of course.


You could however instead of using your own dt try to change the Time.maximumDeltaTime (and probably Time.maximumParticleDeltaTime as well). However Unity "advices" you to not go outside the range 1/10 and 1/3 (default value is 1/3). So we don't know what happens when you set it to 1/60. Since physics is also affected by this and the default physics step is 1/50 it may completely disable physics or other weird things could happen. You have to try it.


Another way, if the above fails, could be to manually adjust the timeScale to compensate the deltaTime for low framerates. Though it's tricky to find the "right" place where to adjust the timescale. The Script execution order may help here.

 public class LimitDeltaTime : MonoBehaviour
 {
     public float TargetFrameRate;
     
     void Update()
     {
         float scale = Time.unscaledDeltaTime * TargetFrameRate;
         if (scale > 1)
             Time.timeScale = 1f / scale;
         else
             Time.timeScale = 1f;
     }
 }

Note this is untested. Changing the timescale like this could cause other issues. Also keep in mind if you want to change the timescale yourself you have to include that in this script since we set the timescale every frame. Replace the "1f" with your desired timeScale

Comment
Add comment · Show 1 · 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 MacMC · Oct 11, 2018 at 12:48 PM 0
Share

Wow! Thank you for the very thorough answer! I will try these solutions out but it seems to be exactly what I'm looking for.

avatar image
0

Answer by MSavioti · Oct 11, 2018 at 07:14 AM

Have you tried using fixedDeltaTime?

Comment
Add comment · Show 1 · 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 Bunny83 · Oct 11, 2018 at 07:37 AM 0
Share

fixedDeltaTime is just a constant. It never changes unless you change it. It dictates the framerate of the FixedUpdate method.

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

93 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

Related Questions

Jump not framerate independent 3 Answers

Framerate independent character movement 1 Answer

Framerate independent physics (FixedTimestep, FixedDeltaTime) 1 Answer

Framerate independent Movement 2 Answers

FixedUpdate and Time.deltaTime slowe 2 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