Forum rules - please read before posting.

is it possible to catch hold with rotating movables before initiating hotspot?

I have rotating movables with some hotspots. When I turn the object and click is hitting the hotspot it is also run. Could there be a way to calculate click and hold difference and use it to prevent hotspot running if mouse button is not released before some offset?

Comments

  • You can hook into the OnGrabMoveable / OnDropMoveable custom events to record the time difference between grabbing and dropping the moveable object, and manually run the Hotspot interaction if so.

    You'll first have to stop the Hotspot from being interacted with normally, so find the Hotspot's first "Use" interaction and uncheck Enabled in the Hotspot Inspector.

    You can then use a custom script to manually run this Interaction if a drag lasts less than a maximum duration. Something like this:

    using UnityEngine;
    using AC;
    
    public class DraggableHotspot : MonoBehaviour
    {
    
        public DragBase draggable;
        public Hotspot hotspot;
        public float maxTimeForHotspotClick = 0.2f;
        private float grabTime;
    
        private void OnEnable ()
        {
            EventManager.OnGrabMoveable += OnGrabMoveable;
            EventManager.OnDropMoveable += OnDropMoveable;
        }
    
        private void OnEnable ()
        {
            EventManager.OnGrabMoveable -= OnGrabMoveable;
            EventManager.OnDropMoveable -= OnDropMoveable;
        }
    
        void OnDropMoveable (DragBase dragBase)
        {
            if (dragBase == draggable)
            {
                if ((Time.time - grabTime) <= maxTimeForHotspotClick)
                {
                    hotspot.useButtons[0].interaction.Interact ();
                }
            }
        }
    
        void OnGrabMoveable (DragBase dragBase)
        {
            if (dragBase == draggable)
            {
                grabTime = Time.time;
            }
        }
    
    }
    
  • Hi, this script seems to work quite ok. But it also fires the hotspot opposite side of the rotatable. When there's a magazine and there's a note on the other side, you can click the magazine and it will not rotate, but fires the note hotspot on the other side. Also in inventory, if you have an object selected in front and select another for use - it will fire use inventory item use and hotspot almost simultaneously.

    Here's a picture of the inventory:
    https://imgur.com/PorXwDl

  • edited August 2021

    I need more details than these descriptions to understand the problems well enough.

    If you can prepare a scene that demonstrates the issues when it's run, PM it to me and I'll take a look. Include your Managers and any model used for the object / moveable as a .unitypackage file.

  • I'm trying to use this script with right click rotatable interaction. I have a look-at and a inventory-item-use set to a hotspot. But I can't seem to be able to detect which interaction is selected for use. The cursor changes between look-at and inventory item cursor, but I can't find a way to check it.

    This:
    KickStarter.playerCursor.GetSelectedCursorID()
    returns just the look-at cursor and selectedItem is null.

  • Try reading GetSelectedCursor instead, which will return -2 if an inventory item is selected.

    You can also get the currently-selected item with:

    KickStarter.runtimeInventory.SelectedItem
    
  • For some reason I'm getting just the Look-at id all the time. And selected item is null.

  • The cursor changes though.

  • Here's the code:

        void OnDropMoveable (DragBase dragBase)
        {
            if (dragBase == draggable)
            {
                if ((Time.time - grabTime) <= maxTimeForHotspotClick)
                {
                    RaycastHit hit;
    
                    LayerMask mask = LayerMask.GetMask("DragHotspot");
                    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast (ray.origin, ray.direction, out hit, 20.0f) ) {
                        Debug.Log ("hit: " + hit.collider.gameObject.name);
                        selected = hit.collider.gameObject.name;
                        Debug.Log("AC.KickStarter.playerCursor: " + KickStarter.playerCursor.GetSelectedCursorID());
                        Debug.Log("AC.KickStarter.playerInteraction.GetActiveUseButtonIconID: " + KickStarter.playerInteraction.DoesHotspotHaveInventoryInteraction());
                        Debug.Log("GetSelectedCursor: " + KickStarter.playerCursor.GetSelectedCursor());
                        Debug.Log("SelectedItem: " + KickStarter.runtimeInventory.SelectedItem);
    
                        switch (selected) {
                            case "ConsentFormRead":
                                MainObject();
                                break;
                            case "ConsentFormSign":
                                Sign();
                                break;
                        }
                    }
                }
            }
        }
    
  • Here's log:
    hit: ConsentFormSign
    AC.KickStarter.playerCursor: 2
    AC.KickStarter.playerInteraction.GetActiveUseButtonIconID: False
    GetSelectedCursor: 2
    SelectedItem:

    Hotspot has two interactions enabled - LookAt and Pen from the inventory.
    For some reason AC returns false for DoesHotspotHaveInventoryInteraction().

  • It might be a case of the time you're calling such code. AC's regular interaction code isn't used while dragging objects, and since you're calling it as the Draggable is being dropped, it hasn't had a chance to re-initialise.

    Try running those same Console checks in an Update loop to check that they show correctly when hovering over a regular Hotspot without dragging/interacting.

    It might be a case of having to wait a frame after the event (coroutine with "yield return null") or instead hooking into the OnHotspotSelect event.

  • I tried the frame delay, but couldn't get it to work.
    Then I tried to hook on OnHotspotSelect and OnChangeCursorMode, but it seems that cursor hook clears the cursor change although cursor doesn't change. Seems weird. Any ideas?

    Here's the code:

        void OnDropMoveable (DragBase dragBase)
        {
            if (dragBase == draggable)
            {
                if ((Time.time - grabTime) <= maxTimeForHotspotClick)
                {
                    string selected = myHotspot.name;
                    Debug.Log("Pushlogic - selectedCursor: " + KickStarter.playerCursor.GetSelectedCursor() + " - item: " + ((myItem != null) ? myItem.label : "ei" ) );
                    switch (selected) {
                        case "ConsentFormRead":
                            MainObject();
                            break;
                        case "ConsentFormSign":
                            if (myItem == null) {
                                LookAtSign();
                            } else {
                                Sign();
                            }
                            break;
                    }
                }
            }
        }
    
        void OnChangeCursorMode (int cursorID) {
            if (cursorID == -2 && KickStarter.runtimeInventory.SelectedItem != null) {
                myItem = KickStarter.runtimeInventory.SelectedItem;
                Debug.Log("OnChangeCursorMode: " + cursorID + " - selectedObject: " + KickStarter.runtimeInventory.SelectedItem.ToString());
            }
            if (cursorID != -2) {
                Debug.Log("OnChangeCursorMode: " + cursorID);
                myItem = null;
            }
        }
    
        void OnHotspotSelect (Hotspot hotspot) {
            Debug.Log("OnHotspotSelect: " + hotspot.name);
            myHotspot = hotspot;
        }
    
  • I'm using U2020.3.2.22f1 and AC1.74.3

  • edited November 2021

    I'll need to see your Settings and Cursor Managers, as well as the full Inspector of the object, in order to recreate it properly.

    Please also describe the situation you're trying to achieve. What are you looking to do once you know the selected cursor/item at the moment a Draggable is let go?

  • Here are the pics:

    https://imgur.com/1w51yg6
    https://imgur.com/u6NwVmH
    https://imgur.com/VWVdZz0
    https://imgur.com/DLec0ZF

    I'm trying to get inventory interaction to work with a Look-at in a single hotspot. The august version worked if there were only one interaction per hotspot.

  • Where does the draggable component factor in? I need to see the Inspector of the object involved.

  • I'm trying to get inventory interaction to work with a Look-at in a single hotspot.

    I'm not clear on your intent. You want the Use interaction to run when the Inventory item is selected?

    You can't check for the selected item at the moment you drop the Draggable, because the Draggable can only be dragged in the first place if no item is selected.

    For now, stick to running your checks in an Update loop. You can limit it running to only when a specific Hotspot is active, and no object is dragged, with:

    public Hotspot myHotspot;
    void Update ()
    {
        if (KickStarter.stateHandler.IsInGameplay () &&
            !KickStarter.playerInput.IsDragObjectHeld () &&
            KickStarter.playerInteraction.GetActiveHotspot () == myHotspot)
        {
            //
        }
    }
    
  • Here's some pics of the problem:
    https://imgur.com/a/oeiRNzz

    So I'm trying to use battery with an inventory item.

    I've tried to catch the inventory item to use with this:
    void OnChangeCursorMode (int cursorID) {
    if (cursorID == -2 && KickStarter.runtimeInventory.SelectedItem != null) {
    myItem = KickStarter.runtimeInventory.SelectedItem;
    Debug.LogError("OnChangeCursorMode: " + cursorID + " - selectedObject: " + KickStarter.runtimeInventory.SelectedItem.ToString());
    Debug.LogError("ddd: " + myItem.label);
    }
    }

        void OnHotspotInteract (Hotspot hotspot, AC.Button button) {
            Debug.LogError("OnHotspotInteract: " + hotspot.name + " - myitem: " + (myItem == null ? "item" : "noitem") );
            if (myItem != null) interactionMyItem = myItem;
            myHotspot = hotspot;
        }
    

    The actual hostpot interaction is done within OnDropMoveable with a 200ms delay to wait if it's actually grabbing or hotspot interact.

  • Please share the whole code - and explain what the actual issue is, i.e. which part of the code fails.

    If OnHotspotInteract is running, is the interaction not running at that point? You can learn which interaction is running with:

    Debug.Log (hotspot.GetButtonInteractionType (button));
    
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.