Forum rules - please read before posting.

Hotspot Detection Player Vicinity AND Mouse Over

I'd like to trigger hotspots when the player is within a vicinity AND when the mouse is over the hotspot. For example, the player could be near hotspot A displaying of the Use icon for that hotspot. And the cursor/mouse could be over hotspot B displaying the Use icon for that hotspot.

Any ideas how to accomplish this with out-of-the-box functionality or custom scripting?

At first, I tried to hook into the EventManager.OnHotspotInteract event but that only gets triggered based on the Hotspot Detection method (either mouse OR vicinity) so it doesn't help my mouse AND vicinity detection scenario.

If I need to write a custom script to manually to set AC.Kickstarter.playerInteraction.SetActiveHotspot(), is there a way to leverage the underlying AC code to get back of list of hotspot(s) the player is in vicinity of or the mouse is over? Or do I need to write my own duplicate logic which would listen for OnTriggerEnter2D for player proximity and simultaneously do raycasting/or OnMouseOver to detect game objects (hotspots) from the mouse? Finally, how would I know when the user clicks on hotspot A or hotspot B.

Apologies if this has been asked and answered but I could not find it on the forum or wiki. I'm running AC version 1.73.6.

Any advice would be greatly appreciated.

Comments

  • edited April 2021

    Welcome to the community, @zenbend.

    So as I'm clear: you're looking to only allow the player to mouse-over Hotspots that they are currently nearby?

    If so, this should be the default behaviour when using Point And Click movement combined with Player Vicinity hotspot detection.

    If you're using Direct or First Person, you can enable this behaviour by setting your Hotspots in vicinity option to Show All.

    What movement mode are you currently using, or am I misunderstanding your intent?

  • Thanks for the speedy reply! To clarify, I am using Point and Click movement method. And I want the player to be able to discover hotspots/interactions via mouse over (any spots within camera view) and vicinity to player since the player position could be within one hotspot and the mouse/cursor within another hotspot.

    Here is my use case:

    Discovering Interactions

    1. User moves mouse over (but does not click) hotspot A (screen left). Look At icon appears.
    2. Users clicks within hotspot A. Player walks to that point inside hotspot A. Look At icon still appears ready to be clicked.
    3. Now the user moves the cursor/mouse over (but does not click) hotspot B (screen right).
    4. Because player is still within hotspot A, Loot At icon remains visible for hotspot A.
    5. Because mouse/cursor is over hotspot B, Look At icon is also visible for hotspot B.

    Selecting An Interaction

    • If user were to click Look At icon for hotspot B, player would walk toward hotspotB and start hotspot B Look At interaction actions. Since player has left hotspot A, hotspot A Look At icon would naturally disappear. (Neither player or mouse are within hotspot A any longer.)
    • If user were to click Look At icon for hotspot A, hotspot B Look At icon would naturally disappear since the mouse would move out of hotspot B.

    Hope that clarifies and doesn't confuse.

    I'll go back and look at the documentation for the other movement modes, but in my initial readings/exploration of this, I don't think it solves my need. Point and click seemed right. Again, many thanks for any inspiration you have to accomplish this.

  • edited April 2021

    Thanks for the elaboration.

    In that case, it sounds like a custom interaction system is necessary.

    You can leverage some of AC's built-in methods, but your finer points mean it's best to have full control over the whole thing.

    This is a two-pronged problem (discovery vs interaction), I'd recommend starting with just the discovery (selection in AC terminology) aspect first.

    Have a look through the Manual's "Custom interaction systems" chapter, as well as the CustomInteractionSystemExample script, for a general introduciton to the topic. Yours would have to be more complex, however, since the examples still call PlayerInteraction.SetActiveHotspot to update the active Hotspot. In your case, with multiple Hotspots being able to be active simultaneously, you'll need to keep track of which Hotspots are selected as part of your custom script - bypassing AC's PlayerInteraction script.

    If you set your "Interaction method" to "Custom Script", PlayerInteraction's own operations won't be used - leaving you able to interact with/select Hotspots via their public Select, Deselect, RunUseInteraction etc functions. See the Hotspot's entry in the Scripting Guide here for a list of what's available.

    You can still make use of the Player's DetectHotspots component, however: its GetAllDetectedHotspots function will return an array of all Hotspots within it.

    For point-and-click, that's built into PlayerInteraction, but you can adapt its IsMouseOverHotspot function to suit your needs:

    private Hotspot GetMouseOverHotspot ()
    {
        LayerMask hotspotLayerMask = 1 << LayerMask.NameToLayer (KickStarter.settingsManager.hotspotLayer);
    
        Ray ray = KickStarter.CameraMain.ScreenPointToRay (KickStarter.playerInput.GetMousePosition ());
        RaycastHit hit;
    
        if (Physics.Raycast (ray, out hit, KickStarter.settingsManager.hotspotRaycastLength, hotspotLayerMask))
        {
            Hotspot hotspot = hit.collider.gameObject.GetComponent <Hotspot>();
            {
                return hotspot;
            }
        }
        return null;
    }
    

    I can advise further if you need, but have a look through this and see if it helps so far.

  • Thanks for your thoughtful response. I'll give your suggestions a go and see where it leads me before I trouble you any further.

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.