Should I use delta-time to move my camera?

0 favourites
  • 6 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Ashley's 2017 article on delta-time says:

    Don't forget behaviors already use dt. If you use behaviors to control all motion in your game, you don't have to worry about dt at all!

    So, can I ignore delta-time when using the lerp function to position a sprite with the ScrollTo behavior? For context, see the comments in my code below:

    const lerp = (start, stop, amount) => amount * (stop - start) + start;
    
    export default class Game {
     #runtime;
     #camera;
     #player;
    
     start(runtime) {
     this.#runtime = runtime;
     this.#camera = this.#runtime.objects.Camera.getFirstPickedInstance();
     this.#player = this.#runtime.objects.Player.getFirstPickedInstance();
     this.#runtime.addEventListener('tick', () => this.#onTick());
     }
    
     #onTick() {
     // Do I need `this.#runtime.dt` here?
     // Or, does the scrollTo behavior already use it?
     const amount = 0.3 * this.#runtime.dt;
     // Move the camera to the player's position using lerp.
     this.#camera.x = lerp(this.#camera.x, this.#player.x, amount);
     this.#camera.y = lerp(this.#camera.y, this.#player.y, amount);
     }
    }
    
  • Just for clarity, this.#runtime.objects.Camera.getFirstPickedInstance() is a sprite with the scrollTo behavior enabled.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Just for clarity, this.#runtime.objects.Camera.getFirstPickedInstance() is a sprite with the scrollTo behavior enabled.

    I don't know how you read the article. There is this paragraph here:

    It's also a good way to test you have used dt correctly. If you have used it correctly, setting the time scale to 0 will stop everything in the game. If you have not used it correctly, some objects might continue to move, even though the game is supposed to be paused! In that case you can check how those objects are moved, and make sure you are using dt properly.

    You should also read this article: construct.net/en/blogs/ashleys-blog-2/using-lerp-delta-time-924

  • Thanks for your reply! Is it possible to set the time scale to 0 for testing without using an event sheet? It seems like it's not based on this discussion.

  • Thanks for your reply! Is it possible to set the time scale to 0 for testing without using an event sheet? It seems like it's not based on this discussion.

    This hasn't been implemented yet. You can add your offer to the offer platform.

  • For posterity, the suggestion can be voted on here.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)