Forum rules - please read before posting.

Hotspot triggered when moving camera

I have a main camera that can be rotated to look around in the room. I use Touch method.
The problem is, when I drag to rotate the camera and there is a hotspot where the dragging begins, it will select the hotspot.

Question is how to avoid this behaviour?

Settings Manager->Activate Hotspot with double-tap? = false , because I do not want to double tap to goto hotspots

Settings Manager:

Comments

  • edited June 2022

    This'd be a case of using a custom script that:

    1) Disables the interaction system so that default clicks/taps don't register
    2) Manually runs the Hotspot interaction when the touch/click is released

    Try this:

    using UnityEngine;
    using AC;
    
    public class ClickUpInteract : MonoBehaviour
    {
    
        private void Start ()
        {
            KickStarter.stateHandler.SetInteractionSystem (false);
        }
    
        private void Update ()
        {
            if ((Input.GetMouseButtonUp (0) || (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Ended)) && KickStarter.stateHandler.IsInGameplay () && KickStarter.playerInput.GetDragState () == DragState.None)
            {
                Ray ray = Camera.main.ScreenPointToRay (KickStarter.playerInput.GetMousePosition ());
                if (Physics.Raycast (ray, out RaycastHit hit, KickStarter.settingsManager.hotspotRaycastLength, 1 << LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer)))
                {
                    Hotspot hitHotspot = hit.collider.gameObject.GetComponent<Hotspot> ();
                    if (hitHotspot)
                    {
                        hitHotspot.RunUseInteraction ();
                    }
                }
            }
        }
    
    }
    
  • Thanks a lot, that worked great!

  • As earlier said, this worked well as I needed it to work, but unfortunately there is still an issue:
    When I start swipe/drag to move the camera around, and the cursor is over a hotspot (for example a door), the the drag camera stays still until the cursor is outside the hotspot. When cursor is outside a hotspot you can drag seamlessly over any hotspot thereafter, it's just when start dragging the issue is present.
    This can be quite problematic if there is a big hotspot in the scene.

    Please see the video to see what's going on (doors are hotspots):

    PS: I am using the script above, really appreciate that one.

  • I'm afraid I can't recreate the issue on my end - it's possible to move the camera when dragging over Hotspots.

    Can you share screenshots of your Settings Manager, as well as your AC/Unity versions?

  • budbud
    edited July 2022

    Unity version: 2020.3.36f1
    AC version: 1.75.4

    I have also tried to set the "Interaction method" = Custom script, but its the same result.

    Part 1:

    Part 2:

    Part 3:

  • Here is how to reproduce:

    • Use ConstrainedFirstPersonCamera.cs + set "is drag controlled" = true, get script from:
      https://adventure-creator.fandom.com/wiki/Camera_-_Constrained_first-person

    • On any GameObject add the script ClickUpInteract.cs

    • Place a hotspot in the scene, and just add a Use Interaction (No action needed)
      When Editor Play:
      • Try dragging from the middle of the hotspot in either way => Works
      • Click one time on the hotspot
      • Try dragging from the middle of the hotspot in either way => Do not work anymore
  • I still can't reproduce, I'm afraid - following your steps causes no issue on my end.

    Give the latest release a try, v1.75.5, just in case.

    Though, your previous post didn't mention the issue only occuring after clicking a Hotspot. By "do not work anymore", you're still referring to the camera only moving once the mouse has left the Hotspot?

  • I will upload a project in a sec.
    "do not work anymore" means only moving once mouse has left the hotspot, yes.

  • budbud
    edited July 2022

    Here is a more clean version:
    [REDACTED]
    Note: Above file is deleted, use this !
    As previous, green & red boxes are hotspots.

    • Try dragging from the middle of a hotspot in either way => Works: camera moves regardless of where swipe/drag starts
    • Click one time on the hotspot
    • Try dragging from the middle of a hotspot in either way => Do not work: Now, camera only moving once mouse has left the hotspot
  • edited July 2022

    Link removed. AC is a paid-for assets and links to its source code may not be posted on the forum - see the forum rules.

    I downloaded the link before removing it and will take a look.

  • Sorry about that, I actually did not think about it, I have removed the file now.

  • Recreated.

    Seems like the easiest approach is to have the script use its own ray length for detecting Hotspots, and reduce the Settings Manager's Hotspot ray length to zero:

    using UnityEngine;
    using AC;
    
    public class ClickUpInteract : MonoBehaviour
    {
    
        public float rayLength = 20f;
    
        private void Start ()
        {
            KickStarter.stateHandler.SetInteractionSystem (false);
        }
    
        private void Update ()
        {
            if ((Input.GetMouseButtonUp (0) || (Input.touchCount == 1 && Input.GetTouch (0).phase == TouchPhase.Ended)) && KickStarter.stateHandler.IsInGameplay () && KickStarter.playerInput.GetDragState () == DragState.None)
            {
                Ray ray = Camera.main.ScreenPointToRay (KickStarter.playerInput.GetMousePosition ());
                if (Physics.Raycast (ray, out RaycastHit hit, rayLength, 1 << LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer)))
                {
                    Hotspot hitHotspot = hit.collider.gameObject.GetComponent<Hotspot> ();
                    if (hitHotspot)
                    {
                        hitHotspot.RunUseInteraction ();
                    }
                }
            }
        }
    
    }
    
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.