<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Map and marker shaking]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1459</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1459&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Map and marker shaking.]]></description>
		<lastBuildDate>Tue, 10 Mar 2020 08:59:40 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Map and marker shaking]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6058#p6058</link>
			<description><![CDATA[<p>Try replacing in the example:<br /></p><div class="codebox"><pre><code>OnlineMaps.instance.OnUpdateBefore += OnUpdateBefore;</code></pre></div><p>to<br /></p><div class="codebox"><pre><code>OnlineMaps.instance.OnLateUpdateBefore += OnUpdateBefore;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 10 Mar 2020 08:59:40 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6058#p6058</guid>
		</item>
		<item>
			<title><![CDATA[Re: Map and marker shaking]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6057#p6057</link>
			<description><![CDATA[<p>Here is video example: <a href="https://drive.google.com/open?id=1ibQs93eNFUeYW-s5tJ0CQ4h_odU1_zsa">https://drive.google.com/open?id=1ibQs9 … h_odU1_zsa</a></p>]]></description>
			<author><![CDATA[null@example.com (jostikmr)]]></author>
			<pubDate>Tue, 10 Mar 2020 01:04:17 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6057#p6057</guid>
		</item>
		<item>
			<title><![CDATA[Re: Map and marker shaking]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6056#p6056</link>
			<description><![CDATA[<p>Thanks for your response, I keep experimenting with marker rotation and now I noticed strange behaviour of rotation marker with compass. For now I use next settings: <br />- I use marker that created by Location Service class<br />- &quot;Use compass for marker&quot; field enabled<br />- &quot;Lerp compass value&quot; field enabled<br />- value of &quot;Compass threshold&quot; = 0.3<br />For rotating my map with marker I use this example: <a href="http://infinity-code.com/atlas/online-maps/pages/RotateMapInsteadMarkerExample.html">http://infinity-code.com/atlas/online-m … ample.html</a><br />but for some reason my map starts to jitter when I try to change my compass direction to opposite (especially if I do it really fast). I tried to figure out why this happening but for now I came to only one conclusion which lies of marker lerping. I noticed that map jittering when marker still rotating (Lerp is not ended) and at this moment I try to change rotation to opposite side. Maybe this is the reason?</p>]]></description>
			<author><![CDATA[null@example.com (jostikmr)]]></author>
			<pubDate>Tue, 10 Mar 2020 01:02:51 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6056#p6056</guid>
		</item>
		<item>
			<title><![CDATA[Re: Map and marker shaking]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6027#p6027</link>
			<description><![CDATA[<p>Shaking is unstable values from the sensor.</p><p>Why do you think Google Maps handles a change in value even by 1 degree?<br />Can you confirm this, or is it just your thoughts?</p><p>There are several ways to remove shaking:<br />1. The threshold for changing the value.<br />2. Lerp or tween values.<br />3. Collect the last few values (4, 8, 10, 12, etc.), and based on them find the average value. <br />There are many algorithms for calculating the average value, for example: sum / quantity.</p><p>Online Maps Location Service uses options 1 and 2.</p><p>The value 0.02 was selected by the test way.</p><p>How to improve this - try to combine all three ways.<br />Something like:<br /></p><div class="codebox"><pre><code>using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class LerpMarker2 : MonoBehaviour
{
    public float headingThreshold = 0.5f;
    public int maxValues = 4;
    public float lerpValue = 0.08f;

    private float targetHeading;
    private OnlineMapsMarker marker;
    private List&lt;float&gt; headings;
    private bool compassInitialized = false;

    private void Start()
    {
        marker = OnlineMapsMarkerManager.CreateItem(OnlineMaps.instance.position);
        marker.align = OnlineMapsAlign.Center;

        headings = new List&lt;float&gt;();
        OnlineMapsLocationService.instance.OnCompassChanged += OnCompassChanged;
    }

    private void OnCompassChanged(float value)
    {
        compassInitialized = true;
        OnlineMapsLocationService.instance.OnCompassChanged -= OnCompassChanged;
        targetHeading = value * 360;
        marker.rotation = value;
        headings.Add(targetHeading);
    }

    private void Update()
    {
        if (!compassInitialized) return;

        if (headings.Count == maxValues) headings.RemoveAt(0);

        float heading = OnlineMapsLocationService.instance.trueHeading;
        float prevHeading = headings[headings.Count - 1];
        if (prevHeading - heading &gt; 180) heading += 360;
        if (prevHeading - heading &lt; -180) heading -= 360;

        headings.Add(heading);
        heading = headings.Average();

        if (Mathf.Abs(heading - targetHeading) &gt; headingThreshold) targetHeading = heading;

        float targetRotation = targetHeading / 360;
        float rotationOffset = Mathf.Abs(marker.rotation - targetRotation);
        if (rotationOffset &lt; float.Epsilon) return;

        if (rotationOffset &lt; 0.0028) // 1 deg / 360
        {
            marker.rotation = targetRotation;
        }
        else marker.rotation = Mathf.Lerp(marker.rotation, targetRotation, lerpValue);

        OnlineMaps.instance.Redraw();
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 27 Feb 2020 11:11:09 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6027#p6027</guid>
		</item>
		<item>
			<title><![CDATA[Re: Map and marker shaking]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6025#p6025</link>
			<description><![CDATA[<p>Thanks for advice, I decided to use marker that created by Online Maps Location Service. But rotation of marker and&nbsp; camera are smooth too mutch, like with delay. I want to implement rotation of marker like in google maps, where marker rotating when you change compass value even on 1 degree, but without shaking and jerking. I figure out that it&#039;s work much better if set t value in</p><p>value = Mathf.Lerp(value, trueHeading, 0.02f); (OnlineMapsLocationServiceBase.cs, line 614)</p><p>to higher, like 0.08f. Now marker moves without &quot;delay&quot; effect, but still little shaking. Can you explain how to improve it and why you set value of t to 0.02f?</p>]]></description>
			<author><![CDATA[null@example.com (jostikmr)]]></author>
			<pubDate>Wed, 26 Feb 2020 21:32:34 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6025#p6025</guid>
		</item>
		<item>
			<title><![CDATA[Re: Map and marker shaking]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6022#p6022</link>
			<description><![CDATA[<p>Hello.</p><p>lerpCompassValue only works for the marker created by Online Maps Location Service.<br />The true compass value is passed to OnCompassChanged, and you need to smooth this value yourself.</p><p>Example:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class LerpMarker:MonoBehaviour
{
    public float compassThreshold = 0.022f;

    private float compassValue;
    private OnlineMapsMarker marker;
    private bool isFirst = true;

    private void OnCompassChanged(float value)
    {
        float offset = compassValue - value;

        if (offset &gt; 0.5) offset -= 1;
        else if (offset &lt; -0.5) offset += 1;

        if (!isFirst &amp;&amp; Mathf.Abs(offset) &lt; compassThreshold) return;

        isFirst = false;
        compassValue = value;
    }

    private void Start()
    {
        marker = OnlineMapsMarkerManager.CreateItem(OnlineMaps.instance.position);
        marker.align = OnlineMapsAlign.Center;

        OnlineMapsLocationService.instance.OnCompassChanged += OnCompassChanged;
    }

    private void Update()
    {
        float markerRotation = marker.rotation;
        float offset = compassValue - markerRotation;

        if (Mathf.Abs(offset) &lt; float.Epsilon) return;

        if (Mathf.Abs(offset) &lt; 0.003f) markerRotation = compassValue;
        else
        {
            if (offset &gt; 0.5) compassValue -= 1;
            else if (offset &lt; -0.5) compassValue += 1;

            markerRotation = Mathf.Lerp(markerRotation, compassValue, 0.02f);
        }

        marker.rotation = markerRotation;
        OnlineMaps.instance.Redraw();
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 25 Feb 2020 18:58:38 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6022#p6022</guid>
		</item>
		<item>
			<title><![CDATA[Re: Map and marker shaking]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6021#p6021</link>
			<description><![CDATA[<p>Can you make functionality of rotating any of created marker by setting &quot;rotate with compas&quot; on it? Just like it implemented in OnlineLocationService script</p>]]></description>
			<author><![CDATA[null@example.com (jostikmr)]]></author>
			<pubDate>Tue, 25 Feb 2020 16:51:28 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6021#p6021</guid>
		</item>
		<item>
			<title><![CDATA[Map and marker shaking]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=6020#p6020</link>
			<description><![CDATA[<p>Hi<br />I need to implement 2D UI online map with marker which would rotate together with compass so marker always should face forward. But now I have odd shaking of my map and marker. Also I can prevent it by creating marker in OnlineMapsLocationService component while setting &quot;Create Marker&quot; and asign marker rotation to map rotation in separate method and subscribe it to mapsLocationService.OnCompassChanged but that&#039;s not what I need<br />So how I can implement simultaneous rotation of marker (which be instatiated separatly) and map without shaking?<br />Here is exapmle: <a href="https://drive.google.com/open?id=1JOCgzn2FfMUyB9Tb3MSlupPVSDVXd_cm">https://drive.google.com/open?id=1JOCgz … PVSDVXd_cm</a></p>]]></description>
			<author><![CDATA[null@example.com (jostikmr)]]></author>
			<pubDate>Tue, 25 Feb 2020 00:59:10 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=6020#p6020</guid>
		</item>
	</channel>
</rss>
