Topic: How to rotate the camera smoothly by interlocking the compass

We tested it using the "Rotate the camera by compass" example.

During the test, it was confirmed that the camera was disconnected and rotated.

Please let me know if there is a way to move the camera smoothly by linking the compass!

Re: How to rotate the camera smoothly by interlocking the compass

Hello.

Something like that:

using UnityEngine;

namespace InfinityCode.OnlineMapsSupport
{
    public class RotateCameraByCompassExample2 : MonoBehaviour
    {
        public float duration = 1;

        private OnlineMapsCameraOrbit cameraOrbit;
        private float fromAngle;
        private float toAngle;
        private float progress = 1;

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

            cameraOrbit = OnlineMapsCameraOrbit.instance;
        }

        private void OnCompassChanged(float f)
        {
            progress = 0;
            fromAngle = cameraOrbit.rotation.y;
            toAngle = f * 360;
        }

        private void Update()
        {
            if (progress >= 1) return;
            progress += Time.deltaTime / duration;
            
            if (progress > 1) progress = 1;
            
            float angle = Mathf.LerpAngle(fromAngle, toAngle, progress);
            cameraOrbit.rotation = new Vector2(cameraOrbit.rotation.x, angle);
        }
    }
}
Kind Regards,
Infinity Code Team.

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