Hi Everyone!
I was wondering if it’s possible to have the camera pan
x/y values update to dynamic x/y position values? For example…
I need the camera to pan towards the player object. Once the pan is finished, the camera should start following the player. This is the code I’m using:
this.camera.pan(
this.player.x, //How to make dynamic?
this.player.y, //How to make dynamic?
time,
"Sine.easeInOut",
true,
//The camera pan callback
(camera, progress) => {
if (progress === 1) {
camera.startFollow(this.player, false, 0.1, 0.1);
}
}
But the problem I’m having is that the x and y values I set in the pan represent the position of the player at the moment the pan is started. If the player moves while the pan is happening, the camera won’t update to the pan to that new position. So when the pan is finished and startFollow
is called, the camera will jump (jarringly) to point to the player’s current new position. (The lerp
values, 0.1, don’t help to smooth this out - the camera just jumps to the new position, which is actually a bit unexpected. If they did smoothly update to the player’s position I probably wouldn’t even need the pan
effect.)
I’ve tried…
this.camera.pan(
() => this.player.x,
() => this.player.y,
… but no luck there.
I know the callback has x
and y
parameters, but those are ready only.
Does anyone know how to tell the pan to dynamically track the player’s position? (Or, am I overthinking this and there’s a much simpler solution?)