Jump to content

Smooth transition from no camera follow, to camera follow


schmevie15
 Share

Recommended Posts

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

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

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:

Linear.png

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):

Non-Linear.png

Link to comment
Share on other sites

  • 2 years later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...