<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Rotate tileset at center AND follow game object]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1903&amp;type=atom" />
	<updated>2022-01-14T20:41:24Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1903</id>
		<entry>
			<title type="html"><![CDATA[Re: Rotate tileset at center AND follow game object]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8020#p8020" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>digitalrock wrote:</cite><blockquote><p>...<br />I actually would like to use this extra parent hierarchy as I have a sibling which needs to follow along, but not rotate with the tileset map.&nbsp; I figured it would work just fine with the extra parent, but it turns out the solution you provide will only work with the one parent setup.&nbsp; Can you explain how I&#039;d setup the UpdateMap function for this?...</p></blockquote></div><p>I&#039;ve solved what I need here using a different structure, just need to test a little more.&nbsp; In any case, the solution you provided is perfect.</p>]]></content>
			<author>
				<name><![CDATA[digitalrock]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=308</uri>
			</author>
			<updated>2022-01-14T20:41:24Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8020#p8020</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Rotate tileset at center AND follow game object]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8019#p8019" />
			<content type="html"><![CDATA[<p>Thanks Alex, worked amazing. </p><div class="quotebox"><blockquote><p>P.S. In your case, you don&#039;t need two parents. One is enough.</p></blockquote></div><p>I actually would like to use this extra parent hierarchy as I have a sibling which needs to follow along, but not rotate with the tileset map.&nbsp; I figured it would work just fine with the extra parent, but it turns out the solution you provide will only work with the one parent setup.&nbsp; Can you explain how I&#039;d setup the UpdateMap function for this?</p><p>Thanks again Alex, super awesome support.</p>]]></content>
			<author>
				<name><![CDATA[digitalrock]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=308</uri>
			</author>
			<updated>2022-01-14T20:14:01Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8019#p8019</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Rotate tileset at center AND follow game object]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8017#p8017" />
			<content type="html"><![CDATA[<p>Hello.</p><p>In your case, FollowGameObject should be located on the parent GO and UpdateMap method should look like this:<br /></p><div class="codebox"><pre><code>private void UpdateMap()
{
    // Store last position of GameObject
    lastPosition = target.transform.position;

    // Size of map in scene
    Vector2 size = control.sizeInScene;

    // Calculate offset (in tile position)
    Vector3 offset = Quaternion.Inverse(transform.rotation) * (lastPosition - transform.position);
    offset.x = offset.x / OnlineMapsUtils.tileSize / size.x * map.width * map.zoomCoof;
    offset.z = offset.z / OnlineMapsUtils.tileSize / size.y * map.height * map.zoomCoof;

    // Calculate current tile position of the center of the map
    tx -= offset.x;
    ty += offset.z;

    // Set position of the map center
    if (Mathf.Abs(offset.x) &gt; float.Epsilon || Mathf.Abs(offset.z) &gt; float.Epsilon) map.SetTilePosition(tx, ty);

    // Update map GameObject position
    transform.position = lastPosition;
}</code></pre></div><p>P.S. In your case, you don&#039;t need two parents. One is enough.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2022-01-14T19:26:46Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8017#p8017</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Rotate tileset at center AND follow game object]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8016#p8016" />
			<content type="html"><![CDATA[<p>Doing some additional testing and I&#039;m super close.&nbsp; With this hierarchy:</p><p>PositionParent (follow AR camera script)<br />-- RotationParent (compass rotation script)<br />&nbsp; &nbsp;-- Tileset Map</p><p>...and this code:</p><div class="quotebox"><blockquote><p>/// &lt;summary&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; /// Updates map position<br />&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;/summary&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; private void UpdateMap()<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Store last position of GameObject<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lastPosition = target.transform.position;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Size of map in scene<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector2 size = control.sizeInScene;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Calculate offset (in tile position)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector3 offset = lastPosition - transform.position;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; offset.x = offset.x / OnlineMapsUtils.tileSize / size.x * map.width * map.zoomCoof;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; offset.z = offset.z / OnlineMapsUtils.tileSize / size.y * map.height * map.zoomCoof;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Calculate current tile position of the center of the map<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tx -= offset.x;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ty += offset.z;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Mathf.Abs(offset.x) &gt; float.Epsilon || Mathf.Abs(offset.z) &gt; float.Epsilon) map.SetTilePosition(tx, ty);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Update map GameObject position<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var pos = lastPosition;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // assign pos<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; transform.position = pos;<br />&nbsp; &nbsp; &nbsp; &nbsp; }</p></blockquote></div><p>the above seems to work the best so far, only problem being that the tiles/map center moves a little different than what should occur...</p><p>It&#039;s as if the offset should be calculated with respect to the current compass rotation of the map.&nbsp; I&#039;ve notice if I hard-code a ZERO where the compass setting rotates the map, then the map/tiles/ar following all work exactly as expected.&nbsp; With compass angle driving the rotation, this causes the follow script calculations (map.setTilePosition(tx,ty)) to be off comparable/correlated to the angle of rotation of the tileset parent (rotation parent).</p>]]></content>
			<author>
				<name><![CDATA[digitalrock]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=308</uri>
			</author>
			<updated>2022-01-14T18:20:25Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8016#p8016</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Rotate tileset at center AND follow game object]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8014#p8014" />
			<content type="html"><![CDATA[<p>Hi Alex, I have the following hierarchy:</p><p> RotationParent (compass rotation script)<br />&nbsp; &nbsp;-- Tileset Map (follow AR camera script)</p><p>The rotation parent setup allows the compass to rotate the tileset map at its center.&nbsp; This works great.</p><p>I use the FollowGameObject script on the tileset to have the map follow my AR camera.&nbsp; This works great too, but only if the compass rotation script isn&#039;t enabled; otherwise the map will jump out of position AND leaves the parent gameobject behind.</p><p>My problem is I can&#039;t figure out how to get the rotation of the map (at its center) from the compass AND the map follow the AR camera working together.&nbsp; As I said these two features work alone, but not together.</p><p>I tried attaching the followGameObject script to the RotationParent instead of the tileset map, but results were weird.</p><p>I tried adding another parent (for the follow script) using a hierarchy like this:</p><p>PositionParent (follow AR camera script)<br />-- RotationParent (compass rotation script)<br />&nbsp; &nbsp;-- Tileset Map </p><p>...with the following modification to the followGameObject script:</p><div class="quotebox"><blockquote><p>// assign pos<br />&nbsp; //map.transform.position = pos;<br />&nbsp; // try this<br />&nbsp; transform.position = pos;</p></blockquote></div><p>but I&#039;m sure you can imagine nothing I do is working, including this hierarchy.&nbsp; Things come close though.&nbsp; </p><p>Thought I&#039;d see if you could make a suggestion on how to wire this up.&nbsp; Hopefully you can make sense of what I&#039;m trying to do.</p><p>Regards.</p>]]></content>
			<author>
				<name><![CDATA[digitalrock]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=308</uri>
			</author>
			<updated>2022-01-14T04:33:20Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8014#p8014</id>
		</entry>
</feed>
