Camera slowly following y axis of player and then snapping onto him

Hello everyone.
So basically im creating a 2d game where the player can only go up ontop of platforms and can also fall without dying and then trying to get back up. My problem is the camera. Im using the basic camera on perspective mode and i just have a simple script where the camera follows(Vector3.MoveTowards) the y axis of the player so it doesnt go out of bounds. I dont really like the way it looks and feels though. So im basically trying to have the camera slowly follow the y axis of the player and when the player is leaving kinda far and almost out of frame the camera will go closer to him faster or like almost snap close to him. Is there any way to achieve this or something close to it? Is it as simple as some if statements and the distance between the player and the camera?

Yep, you can get the differences of the y position (distance) and lerp using Mathf.Lerp, passing in the distance (scale this down between 0-1) as t.
For tweaking values using a graph, an AnimationCurve might be useful to look into too

1 Like