Hey, so I've implemented a basic zoom function so that when the player and enemy objects are close/far it zooms in/out. The problem now is that I'm looking to implement a smooth transitional zoom rather than an instantaneous change. Here's my code: Code (CSharp): void Update() { playerPosition = GameObject.FindGameObjectWithTag ("Player").transform; enemyPosition = GameObject.FindGameObjectWithTag ("Enemy").transform; if (playerPosition.position.x + 8 > enemyPosition.position.x) { cam.orthographicSize = 5; } if (playerPosition.position.x + 8 < enemyPosition.position.x) { cam.orthographicSize = 10; } } How would I go about making it a smooth change in zoom instead of an instant one? Any help would be greatly appreciated.
look into interpolation: https://docs.unity3d.com/ru/current/ScriptReference/Mathf.Lerp.html so you'd want to do something like: Code (CSharp): if (playerPosition..x + 8 > enemyPosition..x) { cam.orthographicSize = Mathf.Lerp (cam.orthographicSize, 5.0f, Time.deltaTime); }
You could also use Mathf.smoothstep with a bit of tweaking. For anyone who can't use lerp for whatever reason.