playcanvas / playcanvas/engine

Multiple Delta Time

Open
#908 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

In games is very common to has multiples Delta Time for multiple purposes:

  • Scaled Delta Time: for gameplay logic
  • Unscaled Delta Time: for UI logic
  • Physics Delta: Time: for physics logic

In PlayCanvas the update method pass the scaled Delta Time (dt) has a parameter. That is perfect, but sometimes we need an unscaled Delta Time.

The problem
  1. Pause game and set scale time in zero.
    this.app.timeScale = 0;

  2. Pause Menu logic can't use Delta Time to update some elements, because it is in zero.
    UI.prototype.update = function(dt) {
    console.log(dt) // log: 0
    };

The solution (walkaround)

To resolve the problem I calculate the unscaled Delta Time:
this.unscaledDt = (pc.app._time - this.oldTime) / 1000;

How did Unity solve it?

In Unity the update method doesn't pass a Delta Time, it is because the class Time provides multiple Delta Time:

  • Time.deltaTime: The time in seconds it took to complete the last frame (Read Only).
  • Time.unscaledDeltaTime: The timeScale-independent interval in seconds from the last frame to the current one (Read Only).
  • Time.fixedDeltaTime: The interval in seconds at which physics and other fixed frame rate updates (like MonoBehaviour's FixedUpdate) are performed.

https://docs.unity3d.com/ScriptReference/Time.html

The real solution

I believed it could be a good idea to expose the current Delta Time and an unscaled Delta Time in some instance of the PlayCanvas engine, something like this:

  • pc.app.unscaledDeltaTime
  • pc.app.deltaTime

What do you think?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the application update flow around the update(dt) callback, app.timeScale, and the internal app._time value shown in the issue. Check how scaled frame time is computed and passed to scripts, then determine the scope of exposing both scaled and unscaled values. Done should include the proposed app-level timing values and behavior that remains usable when timeScale is zero.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.