Camera Script Help

hey guys i need help with a camera movement script, ive decided to completely restart in my game. heres the script. i want the function to work only once.

if (pc.app.keyboard.isPressed(pc.KEY_ENTER)) {
    setTimeout(this.entity.translateLocal(0,-0.1,0), 100);
    setTimeout(this.entity.translateLocal(0,-0.1,0), 100);
    setTimeout(this.entity.translateLocal(0,-0.1,0), 100);
    setTimeout(this.entity.translateLocal(0,-0.1,0), 100);
    setTimeout(this.entity.translateLocal(0,-0.1,0), 100);
    setTimeout(this.entity.translateLocal(0,-0.1,0), 100);
}

any ideas?

Hi @vilothaine_2,

What are you trying to do?

The code you posted will fire all translateLocal() 100ms after you press the key, at the same instant, not in sequence.

Looks like you want to tween the camera -0.6 downwards (in the y-axis) in the space of 600ms after pressing Enter.

I suspect you should be look at this extension to PlayCanvas:

You’d do something like:

var start = this.entity.getLocalPosition();
var end = start.clone();
end.y -= 0.6;
var tween = this.entity.tween(start).to(end, 0.6, pc.Linear);
tween.start();
3 Likes