Topic: Smoothly zoom to a zoomlevel when clicking a button ?

Hello Alex

Something that I don't understand : the zoom in OnlineMaps.cs is an int. So I can't animate this value with a tween float for instance in Playmaker..

But it is possible to smooth the zoom on mouse event, and I would like to make this possible when I click a button.

I am wondering how I could make a Playmaker Script to be able to zoom smoothly on the map, instead of zooming by increments ?

I could do this with a simulated mouse clic, but this is not very effective, a dedicated action would be much better !

I mean action like "on clic smoothly zoom to this zoomlevel"

Best regards, Phil

Re: Smoothly zoom to a zoomlevel when clicking a button ?

Hello.

Thanks for the bug report.
The problem has been fixed.
I have sent you the updated Playmaker Integration Kit by email.
The next version of the asset will contain this.

Kind Regards,
Infinity Code Team.

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

Re: Smoothly zoom to a zoomlevel when clicking a button ?

Thanks,
We added a public bool everyFrame to this script.
It works fine !
Best regards.
Phil

4 (edited by savvas_6 2023-04-24 17:58:37)

Re: Smoothly zoom to a zoomlevel when clicking a button ?

Hi Alex, I want to add two buttons for zoom in and zoom out. What code should use to achieve a smooth zoom for each button?

Re: Smoothly zoom to a zoomlevel when clicking a button ?

Hi.

Something like that:

using UnityEngine;

namespace InfinityCode.OnlineMapsSupport
{
    public class SmoothZoom : MonoBehaviour
    {
        public float duration = 1;
    
        private float progress = 1;
        private float targetZoom;
        private float startZoom;

        public void ZoomIn()
        {
            progress = 0;
            startZoom = OnlineMaps.instance.zoom;
            targetZoom = OnlineMaps.instance.zoom + 1;
        }
    
        public void ZoomOut()
        {
            progress = 0;
            startZoom = OnlineMaps.instance.zoom;
            targetZoom = OnlineMaps.instance.zoom - 1;
        }

        private void Update()
        {
            if (progress >= 1) return;
        
            progress += Time.deltaTime / duration;
            if (progress >= 1) progress = 1;
        
            float zoom = Mathf.Lerp(startZoom, targetZoom, progress);
            OnlineMaps.instance.floatZoom = zoom;
            OnlineMaps.instance.Redraw();
        }
    }
}
Kind Regards,
Infinity Code Team.

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

Re: Smoothly zoom to a zoomlevel when clicking a button ?

Thank you Alex.

I also add the following to the button function and it works great:

startZoom = OnlineMaps.instance.zoom;

Thank you!

Re: Smoothly zoom to a zoomlevel when clicking a button ?

Yes, you're right, I missed that.
I updated the script in post #2/

Kind Regards,
Infinity Code Team.

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