Support for deltatime

Deltatime is an incredibly useful feature that allows operations to be framerate independant, the most commonly usage of this is for physics operations but it has many more applications.
I would really like to see the inclusion of a way to get the time since the last update so stuff like movement speed can be multiplied by it. (For the record, by physics I mean common stuff like moving about and clipping etc not just complex box2d stuff)

Another usage of this further down the line would be framerate independant animations with the timeline incrementing in real seconds/milliseconds but that’s getting ahead of ourselves.

2 Likes

That sounds like a great idea!

1 Like

@Elf_Ears great suggestion. How would you like to see this integrated?

In the mean time, I’ve set up a demo of this in a wick file by using some scripts on a frame.

Default Script:

// Set a few defaults;
project.currentTime = Date.now();
project.lastUpdate = Date.now();
project.deltaTime = 0; 

Update Script:

// Get the current time
project.currentTime = Date.now();
// See how long it's been between frames.
project.deltaTime = project.currentTime - project.lastUpdate;
// Record the current time to be used later.
project.lastUpdate = project.currentTime;
// display the time it's been between frames.
deltaText.setText(project.deltaTime);

And here’s the file I’m using.

deltaTime.wick (1.4 KB)

2 Likes

Thanks for responding! Personally the best way I’ve seen it implemented is to pass it to the update function as it’s an inherently update based system (Obviously this clashes with wick’s new function system though where the declaration is semi abstracted) but some sort of global function to get the current deltatime would be just as good and still work in 100% of cases, it just wouldn’t deter people from calling it in wierd places which isn’t really a big deal.

1 Like