Hey all,
I’ve been banging my head repeatedly on this seemingly simple task, I don’t know maybe I just fail utterly. The task is to have a Camera Lag AND Lag-Catch-Up effect.
This is for a 2D side scroller/runner type game, the character being a rigidbody2d.
Camera lag is the typical camera following when the player is at some constant speed running forward/right and If the player accelerates the player would appear to be moving forward relative to the Camera up to some position relative to the Viewport.
Camera Lag And Lag-Catch-Up effect is the concept of having the camera lag effect and then Lag-Catch-Up being that the Camera then accelerates and then stays at a constant speed relative to the Player bringing the Player’s position relative to the Screen Viewport back to the original position.
So basically, the Camera Lag and Lag-Catch-Up effect wants to always bring the Player to a specific position relative to the Screen Viewport, but still has a lag effect in both directions giving the effect of acceleration relative to the camera.
The closest I’ve seem to have gotten is by having the Camera Lag code using some lerp or Smoothdamp functions. Then I try to read whether the the player is accelerating relative to the Camera by way of checking the camera.position.x - player.position.x < or = the previous frame’s camera.position.x - player.position.x. (Which…isn’t entirely reliable even with a threshshold because the values bounces around quite a bit and sometimes says it’s accelerating when it’s not really…)
so I have a isAccelerating:boolean variable for that. I have code that checks if it has stopped accelerating. When it does it’s supposed to switch the typical Camera Lag Lerp/Smooth damps function to include an additional offset (Bringing the player back to it’s original screen position, even at it’s new speed)
In the end this approach…was quite a mess and didn’t really work.
If anyone has any suggestions or pointers on how I can achieve this effect, that would be most helpful.