Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

askthedev.com Logo askthedev.com Logo
Sign InSign Up

askthedev.com

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Ubuntu
  • Python
  • JavaScript
  • Linux
  • Git
  • Windows
  • HTML
  • SQL
  • AWS
  • Docker
  • Kubernetes
Home/ Questions/Q 39508
In Process

askthedev.com Latest Questions

Asked: May 6, 20252025-05-06T16:14:40+05:30 2025-05-06T16:14:40+05:30

How can I fix laggy physics when lerping Time.timeScale and ensure consistent performance in built versions?

anonymous user

I’ve been working on a Unity project where I’m trying to implement a cool feature that allows players to experience a “flurry rush” by interpolating the time scale. I thought it would be straightforward, but I’m hitting some major snags, especially when it comes to the physics acting all laggy, particularly when the time scale drops below 1.0.

So, here’s the gist of my code. I have this `TimeLerp` class which takes the target time scale and lerps to it using an animation curve for both entering and exiting this slow-motion effect. When I tested it in the Unity editor, it worked okay—at least, the visuals and timing seemed alright. But when I built the project to test it as a standalone, everything went south. The physics felt off, like objects weren’t responding correctly, and it just seems to lag behind.

I’ve read some forum threads that mentioned the need to adjust `Time.fixedDeltaTime` and `Time.unscaledDeltaTime`, but I’m not totally confident that I got it right in my script. The portion where I set the fixedDeltaTime seems to be the likely culprit, but I’m struggling to get it to feel consistent, both in the editor and the built version.

Here’s the part where I think something’s going wrong:

“`csharp
Time.fixedDeltaTime = Time.unscaledDeltaTime * Time.timeScale / startTimeScale;
“`

Could this be the reason for the laggy physics? I wonder if there’s a better approach or some adjustments I should make!

I’m hoping someone out there can take a look at my code and spot any mistakes or offer advice on how to handle time scaling without ruining the physics calculations. I really want this feature to work smoothly since it’s a big part of the gameplay experience and would make the action so much more intense. Any help would be super appreciated!

  • 0
  • 0
  • 2 2 Answers
  • 0 Followers
  • 0
Share
  • Facebook

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Continue with Google
    or use

    Forgot Password?

    Need An Account, Sign Up Here
    Continue with Google

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. anonymous user
      2025-05-06T16:14:42+05:30Added an answer on May 6, 2025 at 4:14 pm

      The issue you’re facing with laggy physics during time scale interpolation is indeed linked to how Time.fixedDeltaTime is managed in Unity. Normally, fixedDeltaTime must consistently scale proportionally with timeScale to guarantee physics calculations occur at stable and expected intervals. Using Time.unscaledDeltaTime for adjusting fixedDeltaTime isn’t ideal because it’s frame-rate dependent and can introduce variability or inconsistency, leading to physics lag or stutter.

      A better approach involves explicitly setting Time.fixedDeltaTime directly proportional to the scaled value of your desired default physics step. For instance, Unity’s default fixedDeltaTime is typically set to 0.02 (50 physics updates per second at normal speed). Therefore, modifying your fixedDeltaTime adjustment line to something like Time.fixedDeltaTime = defaultFixedDeltaTime * Time.timeScale; helps maintain consistency across scaled time intervals. Additionally, caching the original fixed delta time at initialization and restoring it when time returns to normal is recommended. This ensures physics interactions remain smooth and predictable both in editor and standalone builds.

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. anonymous user
      2025-05-06T16:14:41+05:30Added an answer on May 6, 2025 at 4:14 pm

      Time Scaling Issues in Unity

      It sounds like you’re running into some common issues with time scaling in Unity, especially when it comes to physics. When you change Time.timeScale, it doesn’t automatically adjust everything related to physics, which can lead to the laggy behavior you’re experiencing. The key things to consider here are Time.fixedDeltaTime and how physics updates are managed.

      First off, your line:

      Time.fixedDeltaTime = Time.unscaledDeltaTime * Time.timeScale / startTimeScale;

      This line can cause issues if Time.timeScale goes below 1.0 because unscaledDeltaTime does not account for the change in time flow, leading to inconsistent physics calculations. Instead, try this approach:

      Time.fixedDeltaTime = 0.02f * Time.timeScale; // 0.02f is the default fixedDeltaTime

      This keeps things simpler. It sets your fixed delta time in proportion to the normal time scale, which should help with how physics behave when time scales change.

      Also, if you’re interpolating time with an animation curve, make sure that your transitions are smooth and that you’re updating the physics calculations accordingly. You might want to consider adjusting your time scale gradually rather than instantly to help maintain a more stable experience.

      You might also want to implement a system where you can visually debug how the time scale is affecting your game objects. This can help you to visualize any potential issues that arise during gameplay.

      Remember, debugging time scaling issues can be tricky, so take your time testing different approaches, and tweak your settings until you find something that feels good in both the editor and standalone builds.

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Sidebar

    Recent Answers

    1. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    2. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    3. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    4. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    5. anonymous user on How can I update the server about my hotbar changes in a FabricMC mod?
    • Home
    • Learn Something
    • Ask a Question
    • Answer Unanswered Questions
    • Privacy Policy
    • Terms & Conditions

    © askthedev ❤️ All Rights Reserved

    Explore

    • Ubuntu
    • Python
    • JavaScript
    • Linux
    • Git
    • Windows
    • HTML
    • SQL
    • AWS
    • Docker
    • Kubernetes

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.