schmevie15 Posted April 14, 2016 Share Posted April 14, 2016 Hey all, I'm trying to have a movable character go from no camera follow to camera follow when the game starts, but what happens is that when the camera follow gets called the movement is instant and doesn't look very good. Is there any way to have a smooth rather than instant camera follow transition? Thanks! Link to comment Share on other sites More sharing options...
drhayes Posted April 15, 2016 Share Posted April 15, 2016 Aha! The latest Phaser release (2.4.7) has a linear interpolation property on the camera (lerp). It's not officially out right now but you can get it here: In the game I'm working on now I wrote my own smoothing function by overriding the Phaser.Camera's updateTarget function to slowly adjust the view when outside of the camera deadzone. Something to look into if you don't want to play with 2.4.7 yet? Link to comment Share on other sites More sharing options...
Tom Atom Posted April 15, 2016 Share Posted April 15, 2016 I did not examined new Phaser 2.4.7 examples yet, but generally there are two simple ways how to do LERP for your game camera: 1] move from current position to target position: new_position = lerp(from_positon, to_position, time); This moves it in linear speed fromt start position to end position during time and you have to keep somewhere start position. Here move from -1 to 1: 2] or you can do: new_position = lerp(current_position,to_posiiton, MOVEMENT_TIME * coef * delta); Here you are interpolating from current position to end position. You do not have to keep starting position. MOVEMENT_TIME is some constant and coef is another value to tune it so, it looks good. delta is time elapsed between frames. Movement is non-linear. Starts fast and slows down. Here move from -1 to 1 (it actually never reaches 1, but the difference is negligible): drhayes 1 Link to comment Share on other sites More sharing options...
schmevie15 Posted April 15, 2016 Author Share Posted April 15, 2016 Ahh this is great! I was wondering why this wasn't a built in already! Thanks for the help you two! Link to comment Share on other sites More sharing options...
robbevrhst Posted November 27, 2018 Share Posted November 27, 2018 Is there something similar for phaser 3? The github links don't work anymore either Link to comment Share on other sites More sharing options...
samme Posted November 27, 2018 Share Posted November 27, 2018 Phaser 3 also has camera follow with interpolation. And you can start with a small coefficient and then increase it. Link to comment Share on other sites More sharing options...
Recommended Posts