How to create 0.1 second intervals between code

im trying to make a cutscene for my game where the camera zooms into the game after you close the menu, can someone help?
heres an example:
this.entity.translatelocal(0,0,0)
interval
this.entity.translatelocal(0,0,0)
interval
this.entity.translatelocal(0,0,0)
interval
thanks

You could always use window.setInverval(), though it can be tricky to sync it correctly.

What I would propose is to use the Playcanvas tween library, that lets you animate entities (and the camera) smoothly:

https://developer.playcanvas.com/en/tutorials/tweening/

1 Like

so i tryed
MainCharacter.prototype.update = function(dt) {
if(this.app.keyboard.wasPressed){
this.entity.sprite.frame = 4;
}
if(this.app.keyboard.isPressed(pc.KEY_D)){
this.entity.sprite.frame = 1;
setInterval(isPressed(pc.KEY_D), 10);
this.entity.sprite.frame = 2;
setInterval(isPressed(pc.KEY_D), 10);
}
};
i cant really tell which is a function, can you help me out?

Why use interval when you have dt?
dt is the milliseconds between the call of this update and the last update. Just accumulate the dt unit it is 10 seconds.

Also, in your code, you used wasPressed as a variable, while it is a function.

Try accumulating dt and seeing how much accumulated to determine the state of the code.

oh, thanks :I

i need some help on how to use DT, ive been using JS for about a month now so im not exactly the most experienced.

I’m on mobile, so writing code is tedious

var time=0;
var start=false;

MainCharacter.prototype.update = function(dt) {
if (start)
time+=dt/1000;

if(this.app.keyboard.wasPressed(PC.KEY_D))
start=true;

if(time>1 && time<2)
this.entity.sprite.frame = 1;

if (time>2)
this.entity.sprite.frame = 2;

};

sorry about the tedious code thing, thanks :slight_smile:

Well, hope the effort didn’t go to waste :+1: