Topic: Strange interaction with phone gyroscope and NavMeshAgent

Hi. I have one interesting thing happening and looks like Online Maps asset is a reason of this.

Whats happening:

When I move marker in Update() with :

 navAgent.Move(moveDirection * moveSpeed); 

it works perfectly fine on PC, but when it comes to mobile devices - it does not work correctly: marker moves some distance then if I change phone physical position (tilt a little or lift up/move down) marker instantly snaps back to it's starting point.

Why do I think that it is because of OnlineMaps? Because if I add following lines:

 Vector2 playerGeoPosition = OnlineMapsTileSetControl.instance.GetCoordsByWorldPosition(player.transform.position);
        playerMarker.position = playerGeoPosition; 

marker snaps not to the starting position but to the position that was set by this code.

I do understand why it might snap it's position but why does it snap each time phone gyroscope values change(If I get it right)?

P.S. Don't know why but I've attached screenshot of Map and it's components.

Post's attachments

Attachment icon Screen Shot 2019-11-06 at 8.33.45 PM.png 41.05 kb, 60 downloads since 2019-11-06 

Re: Strange interaction with phone gyroscope and NavMeshAgent

Hello.

This is because you are using NavMeshAgent on the marker that is created by Online Maps Location Service.
With every GPS update, Online Maps Location Service updates the marker’s geographic position (reset your changes).
With every map update, Online Maps resets your Unity World Position changes, and sets the marker to a position based on geographic coordinates.
The map is not updated every frame. Only if something important has changed or you invoked a redraw.

So here are a few things to make this work correctly:
1. Create a marker using Online Maps API.
2. When moving NavMeshAgent, update the marker’s geographic position based on Unity World Position.
3. Listen to OnLocationInited and OnLocationChanged to process GPS changes (if necessary).
http://infinity-code.com/doxygen/online … 79479dbafe

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-11-08 11:56:17)

Re: Strange interaction with phone gyroscope and NavMeshAgent

Thank you for your response. Can you please clarify how gyroscope and GPS interact with each other and what really causes map updates. I do already use OnLocationInited and OnLocationChanged and these events are not called at all if I move less than 10-15 meters.

Re: Strange interaction with phone gyroscope and NavMeshAgent

Gyroscope, GPS and compass do not interact with each other.
These are different features.

GPS (OM Location Service) looks at changes in LocationInfo, and if something has changed, calls OnLocationChanged.
https://docs.unity3d.com/ScriptReferenc … nInfo.html
OnLocationInited is called when the first values appear in LocationInfo.

Civilian GPS has a rather low accuracy (compared to military devices), and depending on the device and the place where you are (in the city or in the open space) it can have a real accuracy of 5-30 meters.

Kind Regards,
Infinity Code Team.

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

5 (edited by fedor 2019-11-11 07:09:06)

Re: Strange interaction with phone gyroscope and NavMeshAgent

Oh, thank you, that's definitely useful info, but not the thing I was wondering about. My bad, I guess I've stated my problem incorrectly. I will try to rephrase it:
I only need to move phone less than 1cm or change it's angle like by 2 degrees and snapping occurs. GPS only updates every 10-15 meters ( and OnLocationChanged is not called ) thus reason of snapping is gyroscope and/or compass

Re: Strange interaction with phone gyroscope and NavMeshAgent

Unfortunately, I do not know what to recommend to you.
You can try to use all sensors (GPS + gyro + compass + accelerometer).
Online Maps does not force you to use the Online Maps Location Service.
You can use any custom solution.

Actually, if your experiment will be successful, you can sell it as an asset.
I think many developers will be interested in increasing accuracy.

Kind Regards,
Infinity Code Team.

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

7 (edited by fedor 2019-11-13 12:06:28)

Re: Strange interaction with phone gyroscope and NavMeshAgent

Nooo, seems like you don't get my question. I will try again: It already happens and I DON'T want it to happen!!! I need for your map to update every 20 real world meters BUT it updates marker position every 5 realworld millimeters and I don't know why! Simple handshake denies movement of the marker!

Re: Strange interaction with phone gyroscope and NavMeshAgent

Ah, got it.
1. Listen to OnLocationChanged.
2. Calculate the distance between the previous location and the new location (OnlineMapsUtils.DistanceBetweenPoints).
3. If the distance is less than 20 meters, ignore this event.
4. If the distance is more than 20 meters, do what you want from this update.

Kind Regards,
Infinity Code Team.

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

Re: Strange interaction with phone gyroscope and NavMeshAgent

Thank you, that would work and whats I do. BUT as I stated before OnLocationChanged is NOT called( I am sure of it because I listen to OnLocationChanged and have counter to increase each time this event happens) because movement of 5mm is too small for GPS to update it's location but map still updates so marker position resets. I do solve this problem by updating the marker’s geographic position based on Unity World Position on each frame though I don't like it because on my opinion it's too much calculations and idealogically is not correct. So I lost my mind trying to figure out why small handshake affects position of marker.

At this point I am thinking on giving up trying to figure out reason of that/

Re: Strange interaction with phone gyroscope and NavMeshAgent

Most likely, the compass causes the map to be redrawn, because on the device the values of this sensor very often jitter.
Online Maps smooths out this jitter, and you may not see it.

You have two ways:
1. Just when you want to start moving GameObject in the scene, turn off the compass (Input.compass.enabled = false).
I have not tried this, but theoretically this should work.
2. Modify the script OnlineMapsLocationServiceBase (line 505), and comment out or delete the map redrawing by compass.
Result:

if (positionChanged/* || compassChanged*/) map.Redraw();
Kind Regards,
Infinity Code Team.

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

Re: Strange interaction with phone gyroscope and NavMeshAgent

Thank you very much, thats what I needed indeed! It definitely helps but only after some time has passed - my guess that loading tiles also calls map.Redraw(). And when all tiles has finished loading - everything is fine!

Thanks again smile