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

Re: Smooth Camera Zoom to Location

Hi.

The code is ok. I would move the latitude and longitude in the tile position instead of the coordinates, but that is not related to your problem.

You can disable texture compression in Tileset / Materials & Shaders / Compress Textures.
This will increase memory usage, but at the same time can noticeably increase performance.
If necessary, you can change this value dynamically to avoid compressing textures at times when you need performance.
https://infinity-code.com/doxygen/onlin … 08ac57001.

What else you can do to increase smoothness:
When starting an animation, simulate moving along your trajectory with a low FPS (e.g. 10 or 5), without passing values to the map.
When zoom changes, create tiles in the visible area so the map will queue them to load.
To find the range of tiles in the visible area, convert the coordinates to a tile position, subtract and add half the number of visible tiles (width / 256, height / 256).
In this case, to avoid unloading the tiles, you will need to lock them when you create them, and unlock them after the end of the animation.
Points of Interest:
https://infinity-code.com/doxygen/onlin … 5140fbf650
https://infinity-code.com/doxygen/onlin … ba46a509b4
https://infinity-code.com/doxygen/onlin … 6f6c73d8fc
https://infinity-code.com/doxygen/onlin … d1845170e0

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Smooth Camera Zoom to Location

Thank you very much! Disabling the compression already helped. Will follow your other advics as well.