0
votes

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!

1
"I want to keep the distance between the player and the right hand side of the screen constant, no matter his running speed, but also keep a smooth camera when he gains the short speed boost on jumping." These two criteria are mutually exclusive, unless you only want smooth camera tracking in the vertical axis.Nick Udell
I understand that, I'll rephrasebbeckford
Ok I've edited the paragraph, I hope that is clearer.bbeckford

1 Answers

0
votes
enter code here
public float smoothSpeed = 0.125f;
public Vector3 offset;
private Vector3 desiredPosition;

void FixedUpdate(){
    Vector3 smoothedPosition = Vector3.Lerp(transform.position, 
                                  desiredPosition, smoothSpeed);
    transform.position = smoothedPosition;    

}

just tweak the offset vector3 and it will works fine i hope that