1 (edited by GamePyro.com 2026-08-31 18:10:10)

Topic: Example Fly Scene change to Fly Plane problems

Hello

I try to use the SimpleAIrplaneController the included AirPlane from that Asset it uses Rigidbody and controller


I can fly but then the Map not Loads   if use the Airplayne Script from your  Demo Scene it gets moved but the Airplane is not controlabble as it uses your scriipt.

If set speed etdc to 0 it works butr then the Airplane Rigidbody not moves only stays same in Center of Map

I tryed the FollowGameObject but then have also stays only in Center of Map

Also tryed modify the FollowGameObject Script to FollowAirGameObject but airplae still fyl in center an not move  as map centers to airplane


if disable aircraft script or the follow gameobject script the Airplane fly but then the Map not loads anymore after reach end of it .

what to worng hope you can help here

FollowAirGameObject script

using OnlineMaps;
using System;
using System.Collections.Generic;
using UnityEngine;

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

        /// <summary>
        /// GameObject to be followed by the map
        /// </summary>
        public GameObject target;

        /// <summary>
        /// Last position of GameObject
        /// </summary>
        private Vector3 lastPosition;

        /// <summary>
        /// Reference to the map
        /// </summary>
        private Map map;

        private MouseController mouseController;

        /// <summary>
        /// Last tile position of the center of the map
        /// </summary>
        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<Point> points;

        private float speed;
        public float altitude = 1000; // meters
        //private Map map;
        private double totalDistance;
        private List<double> 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 && !(control = TileSetControl.instance))
            {
                Debug.LogError("Control not found");
                return;
            }





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

            //mouseController = map.GetComponent<MouseController>();

            //// 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();
        }

        /// <summary>
        /// This method is called when the zoom changes (in this case, using a script or inspector)
        /// </summary>
        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();
        }

        /// <summary>
        /// Updates map position
        /// </summary>
        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 "follow-gamobject" 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) > float.Epsilon || Mathf.Abs(offset.z) > 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 > 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;
        }
    }
}


Also how at Online Maps make Floiting Point Fix?


regards

Re: Example Fly Scene change to Fly Plane problems

Hello.

Something like this:

/*         INFINITY CODE         */
/*   https://infinity-code.com   */

using OnlineMaps;
using UnityEngine;

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

        /// <summary>
        /// GameObject to be followed by the map
        /// </summary>
        public GameObject target;

        /// <summary>
        /// Last position of GameObject
        /// </summary>
        private Vector3 lastPosition;

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

        private MouseController mouseController;

        /// <summary>
        /// Last tile position of the center of the map
        /// </summary>
        private TilePoint tilePoint;

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

            mouseController = map.GetComponent<MouseController>();

            // 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();
        }

        /// <summary>
        /// This method is called when the zoom changes (in this case, using a script or inspector)
        /// </summary>
        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();
        }

        /// <summary>
        /// Updates map position
        /// </summary>
        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;
        }
    }
}

About the floating point issue:
Online Maps cannot fix Unity floating-point precision globally.
For a large flying world you need to use a floating origin approach.
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
This is also the approach I would recommend for an aircraft that can travel long distances.

Kind Regards,
Infinity Code Team.

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