Change field of view over time

I’m trying to smoothly change the camera field of view when my level loads over a 3 second period of time. The camera starts at a 150 field of view and I want it to stop at 55. Along with this I want a countdown to show on the screen like “3”, “2”, “1” and then the level starts. Does that make sense? I’ve tried using the Mathf.Lerp() method, but I can’t get it to work over a set number of seconds. Also what would be the best way to update the countdown timer along with this? If someone could point me in the right direction, that would be great!

I’ll do a bit better than just point you in the right direction :slight_smile:

if you want a proper countdown, there are really only 2 proper ways of doing it: saving the point you start counting, or saving the point you will stop counting. I prefer the latter!

//I presume your using Javascript

var timer:float; //the variable that will be when we stop counting

private var countdown:string = "3"; //the countdown on screen

private var tmp:float; //just a temporary float

function Awake() {
    //first we start the timer
    timer = Time.time + 3; //we set it to 3 seconds in the future
}

function Update() {
    //lets calculate how long till we start
    tmp = timer - Time.time;
    //sets set the countdown string
    if (tmp < 1) {
        countdown = "1";
    }
    else if (tmp < 2) {
        countdown = "2";
    }
    else {
        countdown = "3";
    }
    
    //Now lets properly lerp the Camera fieldofview
    camera.fieldofview = Mathf.Lerp(150, 55, tmp/3); //I don't know if fieldofview is what it's called... I don't have access to the docs right now :)
}

Hope this helps :slight_smile:
Benproductions1