Topic: Smooth Camera Zoom to Location
Hi, I am deeply sorry if this question was already answered, but my search had no results.
I want to realize a smooth camera movement to a specific location on the map. Below my (maybe hacky) code.
IEnumerator MoveCamera(Vector2 coords, int zoom)
{
float currentZoom = OnlineMaps.instance.zoom;
double currentLon;
double currentLat;
OnlineMaps.instance.GetPosition(out currentLon, out currentLat);
while (Mathf.Abs((float)currentLon - coords.y) > 0.01f || Mathf.Abs((float)currentLat - coords.x) > 0.01f)
{
currentLon = Mathf.Lerp((float)currentLon, coords.y, 0.45f);
currentLat = Mathf.Lerp((float)currentLat, coords.x, 0.45f);
currentZoom = Mathf.Lerp((float)currentZoom, zoom, 0.65f);
OnlineMaps.instance.SetPositionAndZoom(currentLon, currentLat, currentZoom);
yield return null;
}
UnlockCamera();
}
This works functionality wise exactly as intended, but unfortunately I get huge dropdowns if the zoom level changes during the camera movement. I looked in the profiler and its specifically: OnlineMaps.Update() / Texture2D.Compress, which is skyrocketing if there are changes in zoom level.
Could you tell me if I use the correct approach to realize this function or if there is any way to improve this bottle-neck.
Thanks,
Danish