Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Low FPS - Best Practises

Discussion in 'Physics for ECS' started by argibaltzi, Feb 27, 2021.

  1. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    Hello
    i have a set of questions on how to best handle timing for a smooth experience, i am using havok if it makes any difference

    Q1
    Should i have an option to select the desired FPS for physics so the player can decide what's best for their system or should use an automatic fps system?

    Q2
    if i set the desired FPS to be 30, is it a good idea to do the following
    a) if the framerate drops below 30 then set FixedTimeStep = Time.deltaTime
    b) if game framerate goes above 30 then keep using 30 PHYSICS FPS

    Q3
    A players computer has an FPS that fluctuates between 30-40 FPS but the PHYSICS FPS=60, what should i do in such cases?

    Q4
    Should i ever bother changing MaximumDeltaTime?

    Q5
    Before FixedTimeSimulationGroup was introduced the physics FPS was tied to the game FPS, if i wanted to achieve that again would i just set at the end of each frame FixedTimeStep = Time.deltaTime ?

    Q6
    The game framerate is 52 but the physics is at 60, whats going to happen here? Will the physics group run twice ? one for the 52 fps and then 1 more to cover the lost 8 fps?


    Thank you!
    ps.
     
  2. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    259
    Q2: I probably wouldn't set Fixed Time Step to delta time. I would have a FPS low fallback time step (like 20 hz) if the given computer is unable to maintain 30 fps.

    Q3: If the player's computer is GPU bound, then probably nothing. The time step will catch up and make sure the game is run deterministically. If the computer is CPU bound, then I would lower the Fixed Time Step to run at 30 hz. I would only cover one of these two cases based on the likelihood your game is going to be GPU or CPU bound based on your minimum / recommended specs.

    Q6: Every so often the Fixed Step will run more than once in a frame to catch up.
     
    Last edited: Feb 28, 2021
  3. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Q1: I'd recommend having predefined fixed time step values that you can use and making sure that your scenes look good on all potential values. Running physics at 20 or 30 Hz is usually just fine, but always test to see what you can expect (don't be afraid to try even lower values).

    Q2: Agreed with desertGhost_, no need to keep physics and rendering in sync.

    Q3, Q6: When physics and rendering framerate differs, there are different ways of "syncing" those positions. Please see \UnityPhysicsSamples/Assets/Demos/2. Setup/2b. Motion Properties/2b7. Motion Properties - Smoothing.unity .

    Q4: MaximumDeltaTime specifies the max number of fixed timestep steps that FixedRateCatchUpManager can try to do in a single frame.

    Q6: I think you'll have a 1 frame "lag" that way, but also don't see what you're going to achieve.

    Recommended reading materials: fixed timestep general explanation, thread about fixed timestep in DOTS .

    Pinging @steveeHavok in case I missed something.
     
  4. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    Q6: what i mean by running at 52fps is (the computer is not strong enough to hit 60fps, so the best it can do is 52). However your timestep is at 60fps. I was just trying to understand what will happen
     
    Last edited: Mar 2, 2021
  5. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Aham, got it. FixedRateCatchUpManager will try to catch up by doing multiple physics steps in 1. I'd highly recommend reading those 2 things linked above, you'll get good detailed explanations for most of the questions.
     
    argibaltzi likes this.
  6. argibaltzi

    argibaltzi

    Joined:
    Nov 13, 2014
    Posts:
    220
    It seems to me that unless the framerate is fairly stable at 60 fps you are better off with a lower physics FPS such as 30 or 40

    Another question with INTERPOLATION smoothing, what happens if your game runs at 60 fps and the physics at 60fps? Will it still be 1 frame behind or will it detect we are in sync and we don't need any interpolation?
     
  7. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Graphics should always be a bit "behind":
    - during the physics step, we will record current and previous physics position and physicsTotalTime
    - graphics has a totally different tick (depends on vsync, not fixed time step, in a separate system group)
    - graphics will calculate how much ahead of physics it is (graphicsTotalTime - physicsTotalTime) and normalize that to [0,1]. Let's call it normalizedTimeAhead
    - graphics will display the body at transform which is interpolated between previous and current physics position, depending on the normalizedTimeAhead

    Without interpolation or extrapolation, graphics will just get the current physics transform.

    The important thing here is to know that graphics and physics ticks are not correlated, can be either 1:1, 1:N or N:1.
     
    argibaltzi likes this.