Smoother camera movement

Hello,

https://playcanvas.com/project/1007902

I have a slider which goes from 0 to 1 and oninput fires the ‘buttonClick’.

This code takes that (as far as I understand) and then uses the variables to move the camera.

This moves the camera to the target location smoothly.

But it only updates the target location once every second.

I am wondering if there is a way to update the targPos variable in such a way that if the slider is continuously moved, the camera moves to the new location smoothly, not in these ‘1 second blocks’.

Thanks!

Hi @Mr_Anderson,

You could use lerping on a Vec3 to smoothly transition from the current position to the target one.

https://developer.playcanvas.com/api/pc.Vec3.html#lerp

Pseudo code to run in your script update method:

this.currentPos.lerp(this.currentPos, this.targetPos, dt * 5);
this.cameraEntity.setPosition(this.currentPos);