Forum rules - please read before posting.

Swiping Activates Hotspot

Hi,

I'm using Camera2DDrag on touch mode (single tap/click). When swiping (i.e. dragging the camera around), if I start swiping from a position where a hotspot is located, the hotspot examine action is triggered. 

How can I avoid this? Maybe by activating hotspots only on mouse up?

Comments

  • edited August 2016
    A two-part problem. You need to prevent Hotspots from being activated, and also allow camera dragging to work when the cursor is over them.

    When using Touch Screen input, there's an option in the Settings Manager named Activate Hotspots with double-tap?.  There isn't such an option for tap/mouse-release, though you could add an input override that would cause mouse/tap releases to work like clicks.

    See this tutorial, but note that the mouse button delegate you want instead is named InputGetMouseButtonDownDelegate.  A similar script could be used to override this delegate, so that mouse up events work as mouse down events.

    The second issue is to allow the camera dragging to work when the mouse is over a Hotspot.  This is checked for specifically in PlayerInput, around line 1630:

    if (!KickStarter.playerInteraction.IsMouseOverHotspot ())
    {
      dragState = DragState._Camera;
      if (deltaDragMouse.magnitude * Time.deltaTime <= 1f && (GetInvertedMouse () - dragStartPosition).magnitude < 10f)
      {
        dragState = DragState.None;
      }
    }

    Here the code is only allowing the camera to be dragged if the cursor is not over a Hotspot.  You could allow this by removing the check:

    dragState = DragState._Camera;
    if (deltaDragMouse.magnitude * Time.deltaTime <= 1f && (GetInvertedMouse () - dragStartPosition).magnitude < 10f)
    {
      dragState = DragState.None;
    }

    Alternatively, you could attach a custom camera dragging script instead - see Section 4.6 in the Manual.
  • edited August 2016
    Hi,

    Thank you for the response. I tried using an InputOverride script with my limited coding skills, and commented out the aforementioned check in PlayerInput. I have no errors but it's not changing anything either so far. Here's my code:

    //////////////////////////////
    using UnityEngine;
    using System.Collections;
    using AC;

    public class InputOverride : MonoBehaviour {

    public string interactionKey = "a";

    void Start () {
    KickStarter.playerInput.InputGetMouseButtonDownDelegate = CustomGetMouseButtonUp;
    }
    private bool CustomGetMouseButtonUp (int button){
    if (button == 0) {
    return Input.GetKey (KeyCode.Mouse0);
    }
    return Input.GetMouseButtonUp (button);
    }
    }
    //////////////////////

    Any tips? 
  • If button 0 is pressed, you're returning its down state - which is what the AC code already does.  Try this:

    if (button == 0)
    {
      return Input.GetMouseButtonUp (0))
    }
    return Input.GetMouseButtonDown (button);

    It may be that instead you'll get a better result by modifying PlayerInteraction.cs instead.  This is the script that actually performs the interaction based on the mouse state - the PlayerInput script merely reads those mouse states in the first place.  In PlayerInteraction, you can find multiple references to MouseState.SingleClick - if you change them to MouseState.LetGo, the Hotspots should instead react to mouse releases.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.