Slow Motion / Timescale?

I’ve seen a couple posts on this topic but none that were resolved or spoke much about a solution. I want to create a global slow motion effect and I currently have a script that runs cc.director.getScheduler().setTimeScale(0.5); but nothing happens when I do this. I’m only using box colliders and no physics. Is there anyway to perform a global slow motion effect? Is this a feature that can be added to the engine if it doesn’t exist?

@slackmoehrle

maybe you know?

@jare and @PP_Pro would know best.

We don’t have this feature yet. It is absolutely a useful feature needs to supply out of the box.

1 Like

@jare Thanks for the response. Any insight how I could create a custom slow motion effect on my own for now? It’s very essential to a Cocos game I’m working on currently.

how about hacking the delta time?

    cc.director.calculateDeltaTime = function (now) {
        if (!now) now = performance.now();
        this._deltaTime = (now - this._lastUpdate) / 1000;
        this._deltaTime *= THE_SPEED_YOU_NEED;
        this._lastUpdate = now;
    },
5 Likes

@jare Thank you! Just tried it and it’s working for my purposes. Appreciate the help :slight_smile:

where exactly I have to make this change, I am using Typescript

@lazydevx I’m using typescript as well, you can wrap everything in a function and call it like this:

setTimeScale(scale) {
    cc.director.calculateDeltaTime = function(now) {
      if (!now) now = performance.now();
      this._deltaTime = (now - this._lastUpdate) / 1000;
      this._deltaTime *= scale;
      this._lastUpdate = now;
    };
  }

A scale of 1 is regular time, scale of 2 is x2 time, scale of 0.5 is half time, etc…

4 Likes

Share myown polyfill to slow motion:

import { Director } from "cc";

const getOrCreateSlomoPolyfill = (() => {
    let polyfill: undefined | { multiplier: number; };

    return () => {
        if (!polyfill) {
            const polyfill_ = { multiplier: 1.0 };
            const tick = Director.prototype.tick;
            Director.prototype.tick = function(dt: number, ...args) {
                tick.call(this, dt * polyfill_.multiplier, ...args);
            };
            polyfill = polyfill_;
        }
        return polyfill;
    };
})();

export function slomo(multiplier: number) {
    getOrCreateSlomoPolyfill().multiplier = multiplier;
}

Usage:

slomo(0.5); // Slow down 0.5x
slomo(3); // Speed up 3x
1 Like