Topic: Smooth Rotate with Camera Rotate to Compass

First off ...I want to thank you for all the help and support I have received since my purchase of your Online Maps plug-in.  I've almost got my setup to the place I need it to be to function for my needs.  Few things I still have not worked out yet.

1.  Get camera to rotate smoothly - After enabing the rotate camera by compass script it seems to rotate in clicks or degrees rather then smooth as one would desire.  After digging into the script I don't see any parameters to up the rotate amount to smooth things out.  Is it possible to achieve this effect?

2.  Off-Set the marker orbit script - I like how this script focuses on to the location service enabled Prefab but what can I do to off center it while still having it rotate.  I'd like it to be in the bottom third of the screen on a mobile device.

3.   Alternatively from using the compass to rotate the camera... what is the best method of rotating the camera by using touch screen methods.  I would use this instead of the compass.  Just want to try all the functions and determine which is best for my application. 

Thank you!
Nate

Re: Smooth Rotate with Camera Rotate to Compass

Also, I'll note I just purchased and enabled Easy-Touch into my build if this resolves the rotate issue.

Re: Smooth Rotate with Camera Rotate to Compass

Hello.

1. Use Mathf.Lerp to smooth the rotation of the camera.
https://docs.unity3d.com/ScriptReferenc … .Lerp.html
Something like:

using UnityEngine;

public class RotateCameraByCompassExample2 : MonoBehaviour
{
    public int speed = 10;

    private OnlineMapsCameraOrbit cameraOrbit;
    private float targetAngle;
    private bool lerpTargetAngle;
    private Vector2 lastRotation;

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

        cameraOrbit = OnlineMapsCameraOrbit.instance;
        lastRotation = cameraOrbit.rotation;
        targetAngle = lastRotation.y;
    }

    private void OnCompassChanged(float f)
    {
        targetAngle = f * 360;
        float angle = cameraOrbit.rotation.y;
        if (angle - targetAngle > 180) targetAngle -= 360;
        else if (targetAngle - angle > 180) targetAngle += 360;

        lerpTargetAngle = true;
    }

    private void Update()
    {
        if (lastRotation != cameraOrbit.rotation) lerpTargetAngle = false;

        if (lerpTargetAngle)
        {
            float newAngle = Mathf.Lerp(lastRotation.y, targetAngle, Time.deltaTime * speed);
            if (Mathf.Abs(newAngle - lastRotation.y) < 0.1)
            {
                lerpTargetAngle = false;
                cameraOrbit.rotation.y = targetAngle;
            }
            else cameraOrbit.rotation.y = newAngle;

            lastRotation = cameraOrbit.rotation;
        }
    }
}

2. Use OnlineMapsCameraOrbit.OnCameraControl to add an offset for the camera.
Something like:

using System;
using UnityEngine;

public class SetCameraOffset : MonoBehaviour
{
    public Vector3 centerOffset = new Vector3(0, 0, -300);
    private OnlineMapsCameraOrbit cameraOrbit;
    private OnlineMaps map;
    private OnlineMapsTileSetControl control;

    private void Start()
    {
        map = OnlineMaps.instance;
        control = OnlineMapsTileSetControl.instance;
        cameraOrbit = OnlineMapsCameraOrbit.instance;
        cameraOrbit.OnCameraControl += OnCameraControl;
    }

    private void OnCameraControl()
    {
        Vector2 rotation = OnlineMapsCameraOrbit.instance.rotation;
        float distance = OnlineMapsCameraOrbit.instance.distance;
        float rx = 90 - rotation.x;
        if (rx > 89.9) rx = 89.9f;

        double px = Math.Cos(rx * Mathf.Deg2Rad) * distance;
        double py = Math.Sin(rx * Mathf.Deg2Rad) * distance;
        double pz = Math.Cos(rotation.y * Mathf.Deg2Rad) * px;
        px = Math.Sin(rotation.y * Mathf.Deg2Rad) * px;

        Vector3 targetPosition = map.transform.position;
        Vector3 offset = new Vector3(control.sizeInScene.x / -2, 0, control.sizeInScene.y / 2);
        offset += Quaternion.Euler(0, rotation.y, 0) * centerOffset;

        if (OnlineMapsElevationManagerBase.useElevation)
        {
            double tlx, tly, brx, bry;
            map.GetCorners(out tlx, out tly, out brx, out bry);
            float yScale = OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry);
            if (cameraOrbit.adjustTo == OnlineMapsCameraAdjust.maxElevationInArea) offset.y = OnlineMapsElevationManagerBase.instance.GetMaxElevation(yScale);
            else offset.y = OnlineMapsElevationManagerBase.GetElevation(targetPosition.x, targetPosition.z, yScale, tlx, tly, brx, bry);
        }

        offset.Scale(map.transform.lossyScale);
        targetPosition += map.transform.rotation * offset;

        Vector3 newPosition = map.transform.rotation * new Vector3((float)px, (float)py, (float)pz) + targetPosition;

        control.activeCamera.transform.position = newPosition;
        control.activeCamera.transform.LookAt(targetPosition);
    }
}

3. Yes, you can try using the touch frameworks.

Kind Regards,
Infinity Code Team.

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

Re: Smooth Rotate with Camera Rotate to Compass

Thanks for the swift response.  Still learning the appropriate methods in customizing the existing scripts.  For the attached solution above am I modifying the existing examples or adding an additional script in addition to the ones I mentioned I am already using?

Re: Smooth Rotate with Camera Rotate to Compass

It is better to create new scripts in order not to lose your changes when updating asset.

Kind Regards,
Infinity Code Team.

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