<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Assign Compass rotation to another GameObject]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=646&amp;type=atom" />
	<updated>2019-12-03T02:35:08Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=646</id>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=5809#p5809" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>renegade.bullet678 wrote:</cite><blockquote><p>Thank you for answering, I fixed the problem. It was quite a hurdle because Im shaky with my trigonometry.</p></blockquote></div><p>Would it be possible to see your solution?&nbsp; I&#039;ve been having the same problem as you and was pulling my hair out.&nbsp; &nbsp;Could you help?&nbsp; PM sent.&nbsp; Thanks.</p>]]></content>
			<author>
				<name><![CDATA[digitalrock]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=308</uri>
			</author>
			<updated>2019-12-03T02:35:08Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=5809#p5809</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2814#p2814" />
			<content type="html"><![CDATA[<p>Thank you for answering, I fixed the problem. It was quite a hurdle because Im shaky with my trigonometry.</p>]]></content>
			<author>
				<name><![CDATA[renegade.bullet678]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=541</uri>
			</author>
			<updated>2017-09-15T15:40:58Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2814#p2814</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2797#p2797" />
			<content type="html"><![CDATA[<p>If you want the north in the application to point to the north in the real world, you need to use a compass.<br />But you will get the wrong compass values in the phone&#039;s vertical orientation.</p><p>Online Maps Location Service is just a wrapper for Unity Location Service and Unity Compass. <br />Online Maps Location Service takes this value from Unity Compass trueHeading.</p><p>Yes, in Google Maps it works much better.<br />But using Online Maps, if you do not like how some feature works (in your case, the compass), you can implement it yourself without modifying the code, and get the behavior that you need.</p><p>I tried to make a script that combined the data from the gyro and the compass, but so far without success. <br />I think this is the right direction to work around the problem. But I can be wrong.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-09-14T00:53:01Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2797#p2797</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2791#p2791" />
			<content type="html"><![CDATA[<p>How do I get true north with only using the gyroscope? What if the user is facing south when the app first starts, the orientation is 0,0,0, but if I have the game object facing north then 0,0,0 will be north while the user is really facing south? Google maps has done it accurately.</p>]]></content>
			<author>
				<name><![CDATA[renegade.bullet678]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=541</uri>
			</author>
			<updated>2017-09-13T07:11:32Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2791#p2791</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2783#p2783" />
			<content type="html"><![CDATA[<p>The compass is used when the phone is placed horizontally (screen up).<br />If you want to use the phone vertically (screen to user) you need to use a gyroscope.<br /><a href="https://docs.unity3d.com/ScriptReference/Gyroscope.html">https://docs.unity3d.com/ScriptReference/Gyroscope.html</a></p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-09-12T20:39:12Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2783#p2783</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2780#p2780" />
			<content type="html"><![CDATA[<p>No problem I attached a video showing the problem with the game camera as the game object to be moved and a video background to show the orientation of the phone properly. See at the beginning the back of the phone is facing down, and I pointed the phone North. The z axis of the camera is rotating according to the compass so at north the map seems flat. When we I move in a circle it moves accordingly. Now when you see me move the phone up to where the screen is facing my face everything becomes troublesome.</p><p>Here is the video, it can&#039;t be attached because it&#039;s too large (10 mb)</p><p><a href="https://www.dropbox.com/s/0gfir9y4q7s3n13/Compass%20Test1.m4v?dl=0">https://www.dropbox.com/s/0gfir9y4q7s3n … 1.m4v?dl=0</a></p>]]></content>
			<author>
				<name><![CDATA[renegade.bullet678]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=541</uri>
			</author>
			<updated>2017-09-12T17:21:39Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2780#p2780</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2779#p2779" />
			<content type="html"><![CDATA[<p>No problem I attached a video showing the problem with the game camera as the game object to be moved and a video background to show the orientation of the phone properly. See at the beginning the back of the phone is facing down, and I pointed the phone North. The z axis of the camera is rotating according to the compass so at north the map seems flat. When we I move in a circle it moves accordingly. Now when you see me move the phone up to where the screen is facing my face everything becomes troublesome.</p>]]></content>
			<author>
				<name><![CDATA[renegade.bullet678]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=541</uri>
			</author>
			<updated>2017-09-12T17:20:04Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2779#p2779</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2778#p2778" />
			<content type="html"><![CDATA[<p>In that case, I do not understand the problem.<br />Please explain in detail what you mean &quot;rotation of my gameobject is veryyyy jerky&quot;, and why the orientation of the phone is important for this problem.<br />Perhaps a video or screenshot will help to understand the problem faster.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-09-12T15:53:35Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2778#p2778</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2777#p2777" />
			<content type="html"><![CDATA[<p>Im still seeing some issues, is it because in my app the phone needs to be used upright in portrait mode, meaning the top of the screen is facing up?</p>]]></content>
			<author>
				<name><![CDATA[renegade.bullet678]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=541</uri>
			</author>
			<updated>2017-09-12T08:12:38Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2777#p2777</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2776#p2776" />
			<content type="html"><![CDATA[<p>Hello.</p><p>The problem is not in your code, and not in Online Maps.<br />The problem is in the sensor values.<br />Use Mathf.Lerp to smooth the values of the compass sensor.</p><p>Something like:<br /></p><div class="codebox"><pre><code>using System;
using UnityEngine;

public class LerpCompassValue:MonoBehaviour
{
    public GameObject cam2;
    private float compassValue;
    private float currentCompassValue;
    private bool isFirstValue = true;

    private void Start()
    {
        OnlineMapsLocationService.instance.OnCompassChanged += OnCompassChanged;
    }

    private void OnCompassChanged(float f)
    {
        currentCompassValue = f;
        if (isFirstValue)
        {
            compassValue = f;
            isFirstValue = false;
        }

        if (currentCompassValue - compassValue &gt; 0.5) compassValue += 1;
        else if (currentCompassValue - compassValue &lt; -0.5) compassValue -= 1;
    }

    private void Update()
    {
        if (isFirstValue) return;
        if (Math.Abs(currentCompassValue - compassValue) &lt; float.Epsilon) return;
        if (Mathf.Abs(currentCompassValue - compassValue) &lt; 0.001f) compassValue = currentCompassValue;
        else compassValue = Mathf.Lerp(compassValue, currentCompassValue, 0.05f);

        OnlineMapsTileSetControl.instance.cameraRotation.y = compassValue * 360;
        Vector3 rot = new Vector3(0f, compassValue * 360f, 0f);

        cam2.transform.eulerAngles = rot;
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2017-09-11T22:53:49Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2776#p2776</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Assign Compass rotation to another GameObject]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=2775#p2775" />
			<content type="html"><![CDATA[<p>Hey I see that you have a script that can rotate the camera according to the compass values, but what if I want to rotate another game object that is not the camera according to the accurate compass values? I tried the following based on your code:</p><p>&nbsp; &nbsp; public class RotateCameraByCompassExample : MonoBehaviour<br />&nbsp; &nbsp; {</p><p>&nbsp; &nbsp; &nbsp; &nbsp; public GameObject cam2;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; private void Start()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Subscribe to compass event<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsLocationService.instance.OnCompassChanged += OnCompassChanged;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;summary&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; /// This method is called when the compass value is changed.<br />&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;param name=&quot;f&quot;&gt;New compass value (0-1)&lt;/param&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; private void OnCompassChanged(float f)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Rotate the camera.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsTileSetControl.instance.cameraRotation.y = f * 360;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector3 rot = new Vector3 (0f, f * 360f, 0f);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cam2.transform.eulerAngles = rot;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }</p><p>The problem is that the rotation of my gameobject is veryyyy jerky. It&#039;s unusable, am I doing it wrong?</p>]]></content>
			<author>
				<name><![CDATA[renegade.bullet678]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=541</uri>
			</author>
			<updated>2017-09-11T20:05:34Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=2775#p2775</id>
		</entry>
</feed>
