Hello
I have a function which eases my camera to a target and works as intended, but this only works for static objects. It calculates the distance upon function call. So if the target was moving any reference to it's position after that is not called so for a fast moving object the camera pans to an out dated location.
This is my current code :
function move(start,target,duration){
var x = target.x - camera.x;
var y = target.y - camera.y;
var startTime = Date.now();
var t,amountX,amountY;
function ease(t, b, c, d) {
t /= d/2;
if (t < 1) return c/2*t*t + b;
t--;
return -c/2 * (t*(t-2) - 1) + b;
};
function update(){
t = Date.now() - startTime;
amountX = ease(t,camera.x,x,duration);
amountY = ease(t,camera.y,y,duration);
update_cameraPosition(amountX,amountY);
if (Date.now() - startTime >= duration){
return;
} else {
setTimeout(update,0);
}
}
setTimeout(update,0);
}
I was wondering, how would I change this so it would pan to a moving target, but also still have an easing motion ?
Hope you can help!