• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML view follow issues

FL1

Member
I'm currently working on a top down adventure game where the view follows the player (original system created by Heartbeast):
Code:
//this Code is in the step Event of the view object

//update view position
view_xview[0]=(x-view_wview[0]/2);
view_yview[0]=(y-view_hview[0]/2);

//move view towards target point
x=lerp(x,target[? "x"],spd);
y=lerp(y,target[? "y"],spd);
Usually, the player is the target and the view's speed is set to 0.5, so the view is always centered on the player.
However, if you set a different target (for instance in a cutscene) and especially when you lower the 'spd' variable, the view gradually slows down when approaching the target, to a point where it moves less than one pixel per step.
I know that this is because of the 'lerp' function. So what i'm trying to do is set a minimum view speed (or rather a minimum distance for the view to move per step), to prevent the view from getting too slow, but without overshooting the target position.
 
Top