1 (edited by YanaAzur 2017-11-28 13:09:56)

Topic: How to rotate the map with one finger?

By default user can pan the map with one finger, and zoom/rotate map with two-finger gesture. I have unchecked "Allow User Control" and "Allow Zoom" options on "Online Maps Tile Set Control" component. Now all user can do is to rotate the map with 2 fingers around current GPS location. Is it possible to change this allowing user rotate the map with single finger?

Re: How to rotate the map with one finger?

Hello.

Yes, you have two ways:
1. Disable Allow Camera Control, and implement your own camera rotation around the map.

2. Something like this:

using UnityEngine;

public class RotateCameraUsingOneFinger:MonoBehaviour
{
    public Vector2 cameraSpeed = Vector2.one;

    private OnlineMapsTileSetControl control;
    private Vector2 lastGestureCenter;
    private bool hasRotation = false;

    private void Start()
    {
        control = OnlineMapsTileSetControl.instance;
        control.allowUserControl = false;
        control.cameraSpeed = Vector2.zero;
    }

    private void Update()
    {
        if (control.GetTouchCount() != 1)
        {
            if (hasRotation)
            {
                hasRotation = false;
                lastGestureCenter = Vector2.zero;
            }
            return;
        }

        hasRotation = true;
        Vector2 center = control.GetInputPosition();
        if (lastGestureCenter == Vector2.zero) lastGestureCenter = center;
        else if (lastGestureCenter != center)
        {
            Vector2 offset = lastGestureCenter - center;
            control.cameraRotation.x -= offset.y / 10f * cameraSpeed.x;
            control.cameraRotation.y -= offset.x / 10f * cameraSpeed.y;
            lastGestureCenter = center;
        }
    }
}
Kind Regards,
Infinity Code Team.

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

Re: How to rotate the map with one finger?

Thank you, Alex! I'll try your solution smile