1 (edited by fedor 2019-09-12 13:11:14)

Topic: Marker Position Changes chaotically after zooming map out

Hi, I have a problem I don't know how to fix, i will describe it and hope there is a way to fix it. In the code I create player

 playerMarker = OnlineMapsTileSetControl.instance.AddMarker3D(position, playerPrefab); 

and I use player camera as the main one. Then at some point I switch to the map view disabling player camera and enabling map camera

     void ActivateMapCamera ()
    {
        playerCamera.depth = 0;
        playerCamera.enabled = false;
        playerCamera.gameObject.SetActive (false);
        initialZoom = OnlineMaps.instance.zoom;
        mapCamera.gameObject.SetActive (true);
        mapCamera.enabled = true;
        mapCamera.depth = 1;
    }

then in script on the mapCamera I have this update function:

    void Update ()
    {
        if (mapControlDisabled)
        {
            if (Input.touchCount == 2)
            {
                OnlineMapsTileSetControl tileSetControl = OnlineMapsTileSetControl.instance;
                tileSetControl.allowUserControl = false;
                Zoom ();
            }
            if (Input.touchCount < 2)
            {
                OnlineMapsTileSetControl tileSetControl = OnlineMapsTileSetControl.instance;
                tileSetControl.allowUserControl = true;
            }
        }
    }

where Zoom() is function which changes mapCamera.orthographicSize. And it contains if-statement which checks if we have zoomed out enough

    void Zoom ()
    {
                ...
        if (mapCamera.orthographicSize == maxOS)
        {
            OnlineMapsTileSetControl tileSetControl = OnlineMapsTileSetControl.instance;
            tileSetControl.allowUserControl = true;
            tileSetControl.allowZoom = true;

            mapControlDisabled = false;
        }
        
        // Change player size to increase visibility on the map
        playerMarker.scale = LerpPlayerScale();
    }

and thats when problem starts : player postion starts rapidly changing (swapping between two positions: actual one and the wrong one) and further map is zoomed out further apart these positions are. Interesting moment that if I remove (comment) whole if-statement then no problems arise, but I need the functionality to change map zoom in comfortable for the user way. I hope I can find help here.

P.S. It is code that was written on the 2.5 version of the Online Maps, but I has updated it to the newest version atm which is 3.5 hoping it would fix the problem but no it didn't.

Re: Marker Position Changes chaotically after zooming map out

Hello.

Typically, chaotic marker movement occurs when you have a map size not equal to N * 256. So first of all, check the size of the map.

Not relevant to your question, but:

The first moment that I see here (actually I do not see, but should have seen) is that you change the active camera, but do not set this camera for the map. This can cause unexpected behaviors.
http://infinity-code.com/doxygen/online … 0f5f0e3b76

The second moment is mapCamera.orthographicSize == maxOS.
https://www.codeproject.com/Articles/38 … -and-relat
It should be something like: Math.Abs (mapCamera.orthographicSize - maxOS) <float.Epsilon.

Kind Regards,
Infinity Code Team.

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

3 (edited by fedor 2019-09-12 13:37:01)

Re: Marker Position Changes chaotically after zooming map out

Thank you for the swift response! My map width is 4096 and height is 4096. Size in Scene is X: 4096 Y: 4096.

Regarding active camera : I have set the MapCamera as the Camera for the Map in the inspector and never change this.

And for second moment : yes, I agree it is better, though mine version works because I have line ( "if (mapCamera.orthographicSize > maxOS) mapCamera.orthographicSize = maxOS;".

Re: Marker Position Changes chaotically after zooming map out

Oh, I think i've found a reason why this happens!! I have a navmesh covering 90% of the map and when I move map PlayerMarker moves with it then at some point marker leaves NavMesh and then postions of the marker begins to alterate between actual postion and closest point on the NavMesh!