1 (edited by digitalrock 2018-01-23 01:28:07)

Topic: How to smooth move Tileset Map

I have a Tileset map with OnlineMapsLocationServices which is used to update the map based on gps input.  I have the distance set to update map every 5m.  What I'd like to do is have the map smooth-move to the new location.  Currently the map (and hence the markers) jump to position on each location change event. 

Is there a way I can control the speed/smoothness of this change in the map center?

I was thinking I could disable Update map position, and then subscribe to the OnGetLocation event.  Then on the event I would attempt to move the map position using lerp. 

Does this sound like the correct way to go about Tileset position changes, or am I way off here?  I figured it would be best to check with you guys.

Thanks, I love your online map asset!!

Re: How to smooth move Tileset Map

Hello.

Yes, this is the correct way.
And it will works much better if you will lerp the tile coordinates of points, instead of geographic coordinates.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

Re: How to smooth move Tileset Map

Thank Alex, that worked great!

One thing though, I'm monitoring the distance and it seems the loc change events are coming approx every 10 meters, however I've set the update distance to 5m.  I've gone as far as modifying the OnlineMapsLocationService.cs

Using this:

    public float updateDistance = 5;

Is there something I'm not doing correct so that I can get loc change events every 5m?  I have verified that I'm not setting the update distance anywhere else in the code and my tileset prefab has update distance set to 5m as well, however update position is not checked (which is why I modify the default in OnlineMapsLocationService.cs)

Here's my modified smooth move code which works great, but the reported distance between moves is always approx 10m:


    public void OnLocationChanged(Vector2 position)
    {
        // from current map position
        fromPosition = OnlineMaps.instance.position;

        // to GPS position;
        toPosition = position;

        double realDistance = OnlineMapsUtils.DistanceBetweenPointsD(fromPosition, toPosition);
        float distance = (float)realDistance * 1000f;
        StartCoroutine(DisplayMessage("moving: "+distance.ToString("F2")+"m"));

        // calculates tile positions
        moveZoom = OnlineMaps.instance.zoom;
        OnlineMaps.instance.projection.CoordinatesToTile(fromPosition.x, fromPosition.y, moveZoom, out fromTileX, out fromTileY);
        OnlineMaps.instance.projection.CoordinatesToTile(toPosition.x, toPosition.y, moveZoom, out toTileX, out toTileY);

        // if tile offset < 4, then start smooth movement
        if (OnlineMapsUtils.Magnitude(fromTileX, fromTileY, toTileX, toTileY) < 4)
        {
            // set relative position 0
            angle = 0;

            // start movement
            isMovement = true;
        }
        else // too far
        {
            OnlineMaps.instance.position = toPosition;
        }
    }

Re: How to smooth move Tileset Map

Changing this value in the script does nothing, because this field is already serialized and still uses the value from the inspector.
Just change «Online Maps Location Service / Desired Accuracy» using Inspector.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

5 (edited by digitalrock 2018-01-24 19:39:35)

Re: How to smooth move Tileset Map

Desired Accuracy is (and always has been) set at 5m.  So that's not it.

Edit:  Desired Accuracy in the Inspector is 5m, but the default in OnlineMapsLocationService.cs is 10.

I will do a test and see after changing the default.

Re: How to smooth move Tileset Map

Two parameters are affect to the accuracy of GPS:
Desired Accuracy and "Update Map Position / Update Distance".
https://docs.unity3d.com/ScriptReferenc … Start.html
Try to increase Update Distance.

Thank you for your question.
I noticed that this is incorrectly grouped in the inspector.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

7 (edited by digitalrock 2018-01-24 19:57:46)

Re: How to smooth move Tileset Map

Do you mean increase Update Distance in the Inspector with Update Position unchecked?  Are you wanting me to test whether or not update distance actually works (large or small)?  Okay will do...

Edit:  Update Map Position unchecked because I'm handling the map movement with delegate.

Edit 2:  I'm assuming that update distance every 5m is accurate give or take (plus or minus) 5m.  Essentially I might be getting the 5m I'm looking for, but add the +-5m which means could be 10 meters total.

Re: How to smooth move Tileset Map

1. Enable Update Map Position.
2. Change Update Distance value.
3. Disable Update Map Position.

Or you can switch the inspector to debug mode, and change this value.

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!

9 (edited by digitalrock 2019-05-31 03:50:19)

Re: How to smooth move Tileset Map

Hi Alex,

I think there's a problem with the smooth move map code, because no matter what I set the time to (3, 6, 15), the map always moves in 2 or 3 seconds.  The code is based on GPS location change event.  "Update Map" is unchecked for the GPS Location Changed script. 

I have 3D markers which I see move with the map.  They always seem to move at the same speed.  I want to see them move sloooowly.  I'm exaggerating here, but at this point I'm just trying to test different cases, and nothing seems to make a difference in the speed of the move.  The map has already moved into position and yet the debug message on-screen is still ticking down the seconds.

Do you know what could be wrong, or how can a I slow down the map move? 

    public void OnLocationChanged(Vector2 position)
    {
        var tileOffset = TileOffset();

        // from current map position
        fromPosition = OnlineMaps.instance.position;

        // to GPS position;
        toPosition = position;

        double realDistance = OnlineMapsUtils.DistanceBetweenPointsD(fromPosition, toPosition);
        float distance = (float)realDistance * 1000f;
        //StartCoroutine(DisplayMessage("moving: " + distance.ToString("f1") + " m"));
        //_message = "moving: " + distance.ToString("f1") + " m";
        _movingMessage = "moving: " + distance.ToString("f1") + " m";
         
        // calculates tile positions
        moveZoom = OnlineMaps.instance.zoom;
        OnlineMaps.instance.projection.CoordinatesToTile(fromPosition.x, fromPosition.y, moveZoom, out fromTileX, out fromTileY);
        OnlineMaps.instance.projection.CoordinatesToTile(toPosition.x, toPosition.y, moveZoom, out toTileX, out toTileY);

        // if tile offset < 4, then start smooth movement
        if (tileOffset < 4)
        {
            // set relative position 0
            angle = 0;

            // start movement
            isMovement = true;

            stopwatch.Reset();
            stopwatch.Start();
        }
        else // too far
        {
            OnlineMaps.instance.position = toPosition;
        }
    }
    private void Update()
    {
        // if not movement then return
        if (!isMovement)
            return;

        // update relative position
        angle += Time.deltaTime / time;    // time = 3, 6, or 15 seconds, but  always moves map in what seems like 2 or 3 seconds 

        if (angle > 1)
        {
            // stop movement
            isMovement = false;
            angle = 1;
        }
        else
        {
            _message = _movingMessage + " in " + (stopwatch.ElapsedMilliseconds / 1000).ToString() + " seconds";
        }

        // Set new position
        double px = (toTileX - fromTileX) * angle + fromTileX;
        double py = (toTileY - fromTileY) * angle + fromTileY;
        OnlineMaps.instance.projection.TileToCoordinates(px, py, moveZoom, out px, out py);
        OnlineMaps.instance.SetPosition(px, py);
    }

Edit: Distance being moved is not much, typically about 5 to 10 meters.

Re: How to smooth move Tileset Map

Alex Vertax wrote:

Hello.

Yes, this is the correct way.
And it will works much better if you will lerp the tile coordinates of points, instead of geographic coordinates.

After doing more testing on the code from my last post, I see that the difference in the "to" and "from" geographic coordinates is so small that your earlier post starts to make a lot more sense.

The question now becomes, how do I lerp using the tile coordinates of "points" instead?

This is how I'll attempt it:

    void Update()
    {
        //if (!_collider.isTrigger) return;

        if (!isMovement) return;

        // update relative position
        angle += Time.deltaTime / time;

        if (angle > 1)
        {
            // stop movement
            isMovement = false;
            angle = 1;
            //_message = "";

        }
        else
        {
            _message = "from: "+fromPosition + " to: " + toPosition+ " in " + (stopwatch.ElapsedMilliseconds / 1000).ToString() + " seconds";
        }

        OnlineMaps.instance.position = Vector2.Lerp(fromPosition, toPosition, angle);

    }

Re: How to smooth move Tileset Map

The above doesn't work to move the map/markers slower for the 10 m distance either as I'm sure you can already tell by looking at it. 

I am still only seeing updates to the location changed events happening every 10 m, not the 5 m I have requested in the Location Service script.  I've tried turning on the "Update Map", then change distance to 5, then turn-off "update Map".  I've turned on Debug mode in Inspector and the update distance is 5.

Re: How to smooth move Tileset Map

About post #9:
The code looks fine.
Please send the full script so I can test it.

About post #10:
Your question seems strange to me, because in post #9 you Lerp tile position.

About post #11:
GPS accuracy depends on many parameters, and can vary greatly on different devices.
Setting the desired accuracy of 5 meters does not guarantee that you will have such accuracy.
https://gis.stackexchange.com/questions … acy-of-gps
https://www.gps.gov/systems/gps/performance/accuracy/

Kind Regards,
Infinity Code Team.

Do not know the best way to thank the developer? Rate the asset in Asset Store!