There are various posts floating around regarding panning/zooming but all of the ones i have read are for scroll wheel / pinch zooming.
I am trying to zoom the camera automatically similar to what Angry Birds does when you launch the birds, the camera pulls back slightly.
I have tried Mathf.lerp(start,end,time), however it just does it instantly.
I’m not sure where i am going wrong, any help would be highly appreciated.
cam.orthographicSize = Mathf.Lerp(5f,9f,6f * Time.time);
where/how are you calling that line of code?
lerp is purely a math function which works out a mid point between two values based on the third parameter. You need to use that function correctly to get an “effect over time”, such that the third parameter changes frame on frame etc.
It’s being called in a function that’s called once when the play releases their finger.
I’m a newbie when it comes to 2D so any help pointing me in the correct location would be awesome, im trying (as you can tell from my mistake) to pan the camera size from 5 → 9.
Thanks in advance.
Just an update as this was giving me so much grief, i am now doing it via Animator and keyframing my positions which is working well.
Animating parameters from a start value to an end value over time is called “tweening”. DOTween is framework for tweening. imho, it’s the best tool on the Asset Store for this purpose. Have a look:
The third parameter of Lerp is a number from 0 to 1. 0 is the start number (5) and 1 is the end (9). So 0.5 will be in between. It’s important you learn that at some point.
You have to animate a number (by adding to it over time) from 0 to 1 by hand, or use the cheap Time.deltaTime way which gives a smooth effect, but isn’t the best way to do it.