Scripting: If velocity goes up, do this...

First of all, hi there!

I'm trying to change my camera's orthographicSize as its target speeds up and slows down. Right now my "if" statement checks to see if the forward velocity of the target is above 8, and if it is, it slowly raises the camera's orthographicSize with a Mathf.Lerp operation, and when the forward velocity goes below 8, it decreases it.

This is not really giving me the effect I want though. Instead, I would like to check if the target's velocity is going up or down. I think I need to check the current forward velocity against last frame's forward velocity, that way I will know if the target's velocity is increasing or decreasing after each frame.

In the end, here's what I'm after:

"If target velocity is increasing, then start zooming out, else if target velocity is decreasing, start zooming in."

This way the faster my target goes, the more the camera will zoom out, and the slower it goes, the more it zooms in. I'm not quite sure how to check if the velocity is increasing or decreasing relative to the last frame's numbers.

Any advice would be really helpful and appreciated! Thanks :)

Maybe you just want to map orthographic size based on velocity?

function Update () {
    camera.orthographicSize = Mathf.Lerp (minZoom, maxZoom, Mathf.InverseLerp (0.0, maxVelocity, rigidbody.velocity.magnitude));
}