I'm working on a constant runner sidescrolling game, the player is constantly moving left to right at an ever-increasing speed, and when the player jumps he gains some extra speed for a limited time.
My camera follow code is as follows (C#):
float dampTime = 0.2f;
Vector3 positionVelocity = Vector3.zero;
void LateUpdate() {
transform.position = Vector3.SmoothDamp(transform.position, targetPos, ref positionVelocity, dampTime);
}
Now this works fine at low speed, the camera follows smoothly when the player jumps. However as the player's speed increases the camera gets more and more left behind, with the player moving more and more to the right hand side of the screen.
I want to keep the distance between the player and the right hand side of the screen constant when he is on the ground nomatter his running speed, but when he jumps and gains the short speed boost the camera should handle it smoothly rather than lurch forwards.
How is this possible?
Thanks!