<?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 — Example Fly Scene change to Fly Plane problems]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=2430</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2430&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Example Fly Scene change to Fly Plane problems.]]></description>
		<lastBuildDate>Tue, 01 Sep 2026 12:06:34 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Example Fly Scene change to Fly Plane problems]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9996#p9996</link>
			<description><![CDATA[<p>Hello.</p><p>Something like this:<br /></p><div class="codebox"><pre><code>/*         INFINITY CODE         */
/*   https://infinity-code.com   */

using OnlineMaps;
using UnityEngine;

namespace OnlineMapsExamples
{
    /// &lt;summary&gt;
    /// How to make the map follow GameObject
    /// &lt;/summary&gt;
    [AddComponentMenu(Utils.ExampleMenuPath + &quot;FollowAirGameObject&quot;)]
    public class FollowAirGameObject : MonoBehaviour
    {
        /// &lt;summary&gt;
        /// Reference to the control. If not specified, the current instance will be used.
        /// &lt;/summary&gt;
        public TileSetControl control;

        /// &lt;summary&gt;
        /// GameObject to be followed by the map
        /// &lt;/summary&gt;
        public GameObject target;

        /// &lt;summary&gt;
        /// Last position of GameObject
        /// &lt;/summary&gt;
        private Vector3 lastPosition;

        /// &lt;summary&gt;
        /// Reference to the map
        /// &lt;/summary&gt;
        private Map map;
        
        public AnimationCurve altitudeZoomCurve = AnimationCurve.Linear(0, 19, 1, 13);
        public float maxAltitude = 4000; // meters

        private MouseController mouseController;

        /// &lt;summary&gt;
        /// Last tile position of the center of the map
        /// &lt;/summary&gt;
        private TilePoint tilePoint;

        private void Start()
        {
            // If the control is not specified, get the current instance.
            if (!control &amp;&amp; !(control = TileSetControl.instance))
            {
                Debug.LogError(&quot;Control not found&quot;);
                return;
            }
            
            // Set a reference to the map and control
            map = control.map;

            mouseController = map.GetComponent&lt;MouseController&gt;();

            // Disable the movement and zoom of the map with the mouse
            mouseController.allowUserControl = false;
            mouseController.allowZoom = false;

            // Subscribe to change zoom event
            map.OnZoomChanged += OnChangeZoom;

            // Store tile position of the center of the map
            tilePoint = map.view.centerTile;

            // Initial update the map
            UpdateMap();
        }

        /// &lt;summary&gt;
        /// This method is called when the zoom changes (in this case, using a script or inspector)
        /// &lt;/summary&gt;
        private void OnChangeZoom()
        {
            // Store tile position of the center of the map
            tilePoint = map.view.centerTile;
        }

        private void Update()
        {
            // If GameObject position has changed, update the map
            if (target.transform.position != lastPosition) UpdateMap();
        }

        /// &lt;summary&gt;
        /// Updates map position
        /// &lt;/summary&gt;
        private void UpdateMap()
        {
            // Store last position of GameObject
            lastPosition = target.transform.position;

            Vector2 size = control.sizeInScene;
            MapView view = map.view;
            Transform mapTransform = map.transform;

            // Calculate offset (in tile position)
            Quaternion rotation = mapTransform.rotation;
            Vector3 offset = rotation * (lastPosition - mapTransform.position - control.center);
            offset.x = offset.x / size.x * view.countTilesX * view.zoomFactor;
            offset.z = offset.z / size.y * view.countTilesY * view.zoomFactor;

            // Calculate current tile position of the center of the map
            tilePoint.Add(-offset.x, offset.z);

            // Set position of the map center
            view.centerTile = tilePoint;
            view.zoom = altitudeZoomCurve.Evaluate(lastPosition.y / maxAltitude);

            // Update map GameObject position
            Vector3 newPosition = lastPosition - rotation * control.center;
            newPosition.y = mapTransform.position.y;
            mapTransform.position = newPosition;
        }
    }
}</code></pre></div><p>About the floating point issue: <br />Online Maps cannot fix Unity floating-point precision globally. <br />For a large flying world you need to use a floating origin approach. <br />Keep the aircraft/camera close to (0, 0, 0) and periodically shift the map and other scene objects while keeping the real position as longitude/latitude <br />This is also the approach I would recommend for an aircraft that can travel long distances.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 01 Sep 2026 12:06:34 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9996#p9996</guid>
		</item>
		<item>
			<title><![CDATA[Example Fly Scene change to Fly Plane problems]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9995#p9995</link>
			<description><![CDATA[<p>Hello</p><p>I try to use the SimpleAIrplaneController the included AirPlane from that Asset it uses Rigidbody and controller</p><br /><p>I can fly but then the Map not Loads&nbsp; &nbsp;if use the Airplayne Script from your&nbsp; Demo Scene it gets moved but the Airplane is not controlabble as it uses your scriipt.</p><p>If set speed etdc to 0 it works butr then the Airplane Rigidbody not moves only stays same in Center of Map</p><p>I tryed the FollowGameObject but then have also stays only in Center of Map</p><p>Also tryed modify the FollowGameObject Script to FollowAirGameObject but airplae still fyl in center an not move&nbsp; as map centers to airplane </p><br /><p>if disable aircraft script or the follow gameobject script the Airplane fly but then the Map not loads anymore after reach end of it .</p><p>what to worng hope you can help here</p><p>FollowAirGameObject script<br /></p><div class="codebox"><pre><code>using OnlineMaps;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace OnlineMapsExamples
{
    /// &lt;summary&gt;
    /// How to make the map follow GameObject
    /// &lt;/summary&gt;
    [AddComponentMenu(Utils.ExampleMenuPath + &quot;FollowAirGameObject&quot;)]
    public class FollowAirGameObject : MonoBehaviour
    {
        /// &lt;summary&gt;
        /// Reference to the control. If not specified, the current instance will be used.
        /// &lt;/summary&gt;
        public TileSetControl control;

        /// &lt;summary&gt;
        /// GameObject to be followed by the map
        /// &lt;/summary&gt;
        public GameObject target;

        /// &lt;summary&gt;
        /// Last position of GameObject
        /// &lt;/summary&gt;
        private Vector3 lastPosition;

        /// &lt;summary&gt;
        /// Reference to the map
        /// &lt;/summary&gt;
        private Map map;

        private MouseController mouseController;

        /// &lt;summary&gt;
        /// Last tile position of the center of the map
        /// &lt;/summary&gt;
        private TilePoint tilePoint;


        //public TileSetControl control;
        public float maxSpeed = 270; // km/h
        public float maxAltitude = 4000; // meters
        public GameObject airplane;
        public GameObject internalGO;
        public AnimationCurve altitudeZoomCurve = AnimationCurve.Linear(0, 19, 1, 13);
        public AnimationCurve accelerationCurve = AnimationCurve.EaseInOut(0, 200, 1, 0);
        //public List&lt;Point&gt; points;

        private float speed;
        public float altitude = 1000; // meters
        //private Map map;
        private double totalDistance;
        private List&lt;double&gt; distances;
        private float targetRotation;
        private double progress;
        private float tilt;

        private GeoPoint location;

        private ElevationManagerBase elevationManager;

        private void Start()
        {
            // If the control is not specified, get the current instance.
            if (!control &amp;&amp; !(control = TileSetControl.instance))
            {
                Debug.LogError(&quot;Control not found&quot;);
                return;
            }





            //// Set a reference to the map and control
            //map = control.map;

            //mouseController = map.GetComponent&lt;MouseController&gt;();

            //// Disable the movement and zoom of the map with the mouse
            //mouseController.allowUserControl = false;
            //mouseController.allowZoom = false;

            //// Subscribe to change zoom event
            //map.OnZoomChanged += OnChangeZoom;

            //// Store tile position of the center of the map
         //  tilePoint = map.view.centerTile;





            //
            control = TileSetControl.instance;
            map = control.map;
            elevationManager = control.elevationManager;

            Vector3 position = map.view.center.ToWorld(map);
            position.y = altitude;
            if (elevationManager) position.y *= elevationManager.GetElevationScale() * elevationManager.scale;

            //transform.position = position;
            location = map.view.center;
            //




            // Initial update the map
            UpdateMap();
        }

        /// &lt;summary&gt;
        /// This method is called when the zoom changes (in this case, using a script or inspector)
        /// &lt;/summary&gt;
        private void OnChangeZoom()
        {
            // Store tile position of the center of the map
            tilePoint = map.view.centerTile;
        }

        private void Update()
        {
            // If GameObject position has changed, update the map
            if (target.transform.position != lastPosition) UpdateMap();
        }

        /// &lt;summary&gt;
        /// Updates map position
        /// &lt;/summary&gt;
        private void UpdateMap()
        {
            // Store last position of GameObject
            lastPosition = target.transform.position;

            altitude = target.transform.position.y;

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

            // Calculate offset (in tile position)
           // Quaternion rotation = map.transform.rotation;
            Vector3 offset = lastPosition - map.transform.position - control.center;
            offset.x = offset.x / size.x * map.view.countTilesX * map.view.zoomFactor;
            offset.z = offset.z / size.y * map.view.countTilesY * map.view.zoomFactor;

            // Calculate current tile position of the center of the map
            //tx -= offset.x;
            //ty += offset.z;
            // Calculate current tile position of the center of the map
            tilePoint.Add(-offset.x, offset.z);

            //////////////////////////////  IT IS HERE : ///////////////////////////////////////////////////////////
            // Set position of the map center
            // If i comment this line, It will behave propely when moving along Y axis.
            // But the &quot;follow-gamobject&quot; logic will be broken if i want to move horizontally the aircraft.
              //map.SetTilePosition(-offset.x, offset.z); 

            // Set position of the map center
            //if (Mathf.Abs(offset.x) &gt; float.Epsilon || Mathf.Abs(offset.z) &gt; float.Epsilon) map.view.centerTile = tilePoint;


            // Update map GameObject position
            Vector3 newMapPos = lastPosition - control.center;


            GeoRect rect = map.view.rect;
            Vector2d distances = rect.Distances();

            double mx = rect.width / distances.x;
            double my = -rect.height / distances.y;

            double v = (double)speed * Time.deltaTime / 3600.0;

            double ox = mx * v * Math.Cos(target.transform.rotation.eulerAngles.x * Constants.Deg2Rad);
            double oy = my * v * Math.Sin((360 - target.transform.rotation.eulerAngles.x) * Constants.Deg2Rad);

            location.Add(ox, oy);

            map.view.SetCenter(location, altitudeZoomCurve.Evaluate(altitude / maxAltitude));
            Vector3 d = target.transform.position - control.center;
            map.transform.position = new Vector3(d.x, map.transform.position.y, d.z);
            newMapPos = new Vector3(d.x, map.transform.position.y, d.z);

            if (target.transform.position.y &gt; 100)
            {
                newMapPos.y = target.transform.position.y - 100;
                //map.zoom = altitudeZoomCurve.Evaluate(altitude / maxAltitude);
                // float elevation = ElevationManagerBase.GetUnscaledElevation(p.x, p.z);
                //p.x = control.sizeInScene.x / -2;
                //float zoom = altitudeZoomCurve.Evaluate(altitude / maxAltitude);
                //p.y = Mathf.Max(altitude, elevation) * ElevationManagerBase.GetElevationScale(map.view.rect, control.elevationManager);
                //map.view.SetCenter(target.transform.position.longitude, position.latitude, zoom);

            }
            else
            {
                newMapPos.y = 0;
            }

            map.transform.position = newMapPos;
        }
    }
}</code></pre></div><br /><br /><p>Also how at Online Maps make Floiting Point Fix?</p><br /><p>regards</p>]]></description>
			<author><![CDATA[null@example.com (GamePyro.com)]]></author>
			<pubDate>Mon, 31 Aug 2026 16:26:06 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9995#p9995</guid>
		</item>
	</channel>
</rss>
