Hi,
I’m trying to have my camera move downwards in an increasing velocity, and have it follow the character if it falls faster than the current velocity. My issue is that the character looks to be teleporting instead of falling, and I think it’s the camera that causes this to happen since the player is falling through normal gravity.
This is my camera script:
public class CameraFollow : MonoBehaviour {
[SerializeField] Rigidbody2D rb;
float speed = 2f;
float threshold = 2.5f;
bool updateSpeed = true;
void Start() {
StartCoroutine("UpdateSpeed");
}
void Update() {
if(rb.transform.position.y < transform.position.y - threshold) {
transform.Translate(new Vector3(0, (rb.transform.position.y - transform.position.y) * 10 * Time.deltaTime, 0));
} else {
transform.Translate(new Vector3(0, -speed * Time.deltaTime, 0));
}
}
IEnumerator UpdateSpeed() {
while(updateSpeed) {
if(speed <= 3) {
speed += 0.05f;
} else if(speed <= 5) {
speed += 0.025f;
} else if(speed <= 7) {
speed += 0.0125f;
} else {
updateSpeed = false;
}
yield return new WaitForSeconds(0.5f);
}
}
}
Any idea how I can fix this, or how I can improve the script?
Thanks in advance!