Camera zoom out relative to player's speed

Hello!

I have a pretty basic camera script, but when my player speeds up I want my camera to zoom out to compensate, and vice versa.

If anyone knows how to do this please help, and if possible try to explain the logic behind it. Thanks!


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour {

public GameObject player;
private Vector3 offset;

// Use this for initialization
void Start () {
    offset = transform.position - player.transform.position;
}

// Update is called once per frame
void LateUpdate () {
    transform.position = player.transform.position + offset;
    
}

}

So, you need to increase offset when your player speeds up. So do it ! ;d
I don’t see any code increasing player’s speed there.
You can try something like this:

PlayerScript _player; to make reference to player controller script,

_player.GetComponent<PlayerScript>(); in Awake or Start method to get this script

transform.position = player.transform.position + (offset * _player.speed); it’ll adjust offset to player’s speed.