1 (edited by digitalmkt 2022-06-21 11:18:56)

Topic: 2D marker rotation

Hi Alex, I´m trying to use CameraOrbit with 2D markers but when I turn 180 degrees the markers keep upsidedown. Any way to make the 2D markers rotate the opposite way like User Locations does?

Thank you very much!

Post's attachments

Attachment icon IMG_7081.jpg 74.7 kb, 47 downloads since 2022-06-21 

Re: 2D marker rotation

Hello.

Example:

using UnityEngine;

public class RotateMarkersByCamera : MonoBehaviour
{
    private OnlineMapsCameraOrbit cameraOrbit;

    private void Start()
    {
        cameraOrbit = OnlineMapsCameraOrbit.instance;
        cameraOrbit.OnCameraControl += OnCameraControl;
    }

    private void OnCameraControl()
    {
        foreach (OnlineMapsMarker m in OnlineMapsMarkerManager.instance)
        {
            m.rotation = cameraOrbit.rotation.y / 360;
        }
        OnlineMaps.instance.Redraw();
    }
}
Kind Regards,
Infinity Code Team.

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

3 (edited by digitalmkt 2022-06-22 07:38:19)

Re: 2D marker rotation

Thank you very much. The code above works by rotating the 2Dmarks, but the markers also don´t stop spinning when I move the device around and deaccelerate to spinning up to the position, like a helicopter. I tried to change the code below to control the 2DMarker Lerp but when I drag the map only the 2Dmarkers (including the Player) move but the map is still frozen.

public class RotateMarkersByCamera : MonoBehaviour
{
    private OnlineMapsCameraOrbit cameraOrbit;
    private OnlineMapsMarkerManager marker;

    private void Start()
    {
        cameraOrbit = OnlineMapsCameraOrbit.instance;
        marker = OnlineMapsMarkerManager.instance;
        cameraOrbit.OnCameraControl += OnCameraControl;
    }

    private void OnCameraControl()
    {
        foreach (OnlineMapsMarker m in OnlineMapsMarkerManager.instance)
        {
            float markerRotation = m.rotation.y;
            var markerRotationY = Mathf.Lerp(markerRotation, cameraOrbit.rotation.y, cameraOrbit.speed.y);
            m.rotation = markerRotationY;
        }
        OnlineMaps.instance.Redraw();
    }

Attached is a video of the spinning markers before my changes.

Thanks again.

Post's attachments

Attachment icon markersSpinning__.mp4 138.96 kb, 63 downloads since 2022-06-22 

Re: 2D marker rotation

Oops... I forgot that marker.rotation takes values from 0 to 1 and cameraOrbit.rotation.y gives values 0-360.
Updated the script in post 2.

Kind Regards,
Infinity Code Team.

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

5 (edited by digitalmkt 2022-06-22 09:50:12)

Re: 2D marker rotation

Perfect!! it´s running like a charm now! The 2Dmarkers are keeping the orientation while moving the device. Thanks for the help.