Forum rules - please read before posting.

Locking cursor in different location

edited August 2020 in Technical Q&A

Hey there -

Is there a method of locking the cursor to a different location other than center of screen? I want to lock it to the lower left of the screen to be completely out of the way as I'm still getting mouse input when I move my game over to game controller mode, even though I have the cursor locked/disabled.

thanks

Comments

  • You can override the locked cursor position by replacing the GameEngine object's Player Input component with a custom subclass of PlayerInput that overrides its LockedCursorPosition property, i.e.:

    using UnityEngine;
    
    namespace AC
    {
    
        public class MyPlayerInput : PlayerInput
        {
    
            protected override Vector2 LockedCursorPosition
            {
                get
                {
                    return Vector2.zero;
                }
            }
        }
    }
    

    Though, inputs mapped to the Mouse X and Mouse Y axes will still recieve input from the mouse regardless of the cursor's locked state or position.

    What effect is mouse input having, specifically? Moving the cursor, first-person view, UI controls? Is this coming from an input in Unity's Input Manager, i.e. CursorHorizontal/CursorVertical?

  • Thanks Chris. I'll take a look at this and see if I can figure out how to apply this only when I put the game into game controller mode.

    When I switch over to game controller mode, I'm disabling the mouse but it seems like it's still picking up movement and raytraces both in-game and in-menus. I'm using the walking dead interface, so if I go up to a hotspot, open an interaction, and the invisible mouse cursor happens to be on one of the interaction options, it'll highlight it and try to choose that interaction when I click a button on my controller...even if I hit a different interaction button (ie: the Examine interaction is being highlighted by the hidden mouse and I press the button to use the Speak interaction, it'll still try to play the Examine interaction).

    If I move the mouse around with the cursor disabled/hidden, it'll still highlight hotspots and whatnot. If I lock the cursor to the center of the screen, it won't move any more but it'll still cast rays, so if an interaction happens to be in the center of the screen it'll do the same behavior as above.

    I guess my ideal scenario would be when the user switches from mouse & keyboard mode to game controller, it would move the mouse position to the lower left (that's 0,0, right?) and then lock it. I'm doing a number of checks and sets after the user changes input type, so ideally, it could happen at this first step:

    int inputType = GlobalVariables.GetIntegerValue (55);
    
                if (inputType == 0)
                            {
                                    //Set to Optimized for Mouse & Keyboard
                                    AC.KickStarter.cursorManager.cursorRendering = CursorRendering.Hardware;
                                    AC.KickStarter.settingsManager.inputMethod = InputMethod.MouseAndKeyboard;
    
                            }
                            else if (inputType == 1)
                            {
                                    //Set to Optimized for Gamepad
                                    AC.KickStarter.cursorManager.cursorRendering = CursorRendering.Software;
                                    AC.KickStarter.settingsManager.inputMethod = InputMethod.KeyboardOrController;
    
    
                            }
    
                            return 0f;
    

    After this step, I'm checking to see what hotspot interaction method the game is in (there are points where I do close up interactions, so I need to re-enable the mouse cursor, even though in game controller mode it's being driven by the right stick)...Once all of the checks complete, it determines if it disables the cursor via Engine: Manage Systems action.

    Perhaps an alternative would be to create an action that would change the mouse cursor position and locking it there? Is that even possible? If so, I could plug that in after all of my checks.

    Anyway - edge case problem, I know...but something that I'm banging my head on.

  • edited August 2020

    PS: On Unity 5.6.6f2 and AC 1.65.1. Happy to provide more screenshots/code snippets of more of my checks/switches when I go to and from game controller mode if that's helpful.

  • edited August 2020

    Are your Menus using Unity UI? Try switching their Source to Adventure Creator if so - even as a test. Unity UI may be detecting the mouse cursor inappropriately, though the latest AC shouldn't have this problem.

    The method I mentioned above is also a newer feature - if you can, I'd recommend upgrading to the latest AC.

    What's your Settings Manager's "Hotspot detection method" set to? If set to Mouse Over, then the cursor position will still detect Hotspots regardless of its position. You'll need to switch to Player Vicinity or Custom Script to have it ignore the cursor.

    If not the mouse position, how is it you're looking to detect Hotspots when using a controller?

  • Most all of my menus are AC. There are a handful that are Unity but the main ones like the interaction ring and everything is all still AC.

    When I'm in Game Controller mode, I'm using Player Vicinity by default but when I go into the close-up sections, I switch to Mouse Over and back to Player Vicinity when I'm no longer in the close-up sections. When using mouse/keyboard and point & click mode, I'm using that ClickMoveToHotspot custom script that you worked out for me awhile back.

    Here's the code from an action I wrote called ActionHotSpotInteractionType that checks to see what global variables I have in place for control/movement type and hotspot detection:

            override public float Run ()
            {
                int controlType = GlobalVariables.GetIntegerValue (46);
                int hotspotType = GlobalVariables.GetIntegerValue (49);
    
                if (hotspotType == 0)
                            {
                                    //Set to Main
    
                                    if (controlType == 0)
                                    {
                                            //Set to Standard - Camera Relative
                                            AC.KickStarter.settingsManager.movementMethod = MovementMethod.Direct;              
                                            AC.KickStarter.settingsManager.directMovementType = DirectMovementType.RelativeToCamera;
                                            AC.KickStarter.settingsManager.seeInteractions = SeeInteractions.ClickOnHotspot;
                                            AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
                                            AC.KickStarter.settingsManager.interactionMethod = AC_InteractionMethod.ChooseHotspotThenInteraction;
                                            AC.KickStarter.settingsManager.closeInteractionMenusIfPlayerLeavesVicinity = true;
                                    }
                                    else if (controlType == 1)
                                    {
                                            //Set to Alternate - Tank Controls
                                            AC.KickStarter.settingsManager.movementMethod = MovementMethod.Direct;              
                                            AC.KickStarter.settingsManager.directMovementType = DirectMovementType.TankControls;
                                            AC.KickStarter.settingsManager.seeInteractions = SeeInteractions.ClickOnHotspot;
                                            AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
                                            AC.KickStarter.settingsManager.interactionMethod = AC_InteractionMethod.ChooseHotspotThenInteraction;
                                            AC.KickStarter.settingsManager.closeInteractionMenusIfPlayerLeavesVicinity = true;
                                    }
                                    else if (controlType == 2)
                                    {
                                            //Set to Point & Click
                                            AC.KickStarter.settingsManager.movementMethod = MovementMethod.PointAndClick;
                                            AC.KickStarter.settingsManager.closeInteractionMenusIfPlayerLeavesVicinity = false;
                                            AC.KickStarter.settingsManager.seeInteractions = SeeInteractions.ViaScriptOnly;
                                            AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.CustomScript;
                                            AC.KickStarter.settingsManager.interactionMethod = AC_InteractionMethod.CustomScript;
                                            AC.KickStarter.settingsManager.closeInteractionMenusIfPlayerLeavesVicinity = false;
                                    }
    
                            }
                            else if (hotspotType == 1)
                                    {
                                            //Set to MouseOver
                                            AC.KickStarter.settingsManager.hotspotDetection = HotspotDetection.MouseOver;
                                            AC.KickStarter.settingsManager.closeInteractionMenusIfPlayerLeavesVicinity = false;
                                            AC.KickStarter.settingsManager.seeInteractions = SeeInteractions.ClickOnHotspot;
                                            AC.KickStarter.settingsManager.interactionMethod = AC_InteractionMethod.ChooseHotspotThenInteraction;
                                    }
    
    
    
    
                            return 0f;
    
  • You can uncheck Ignore Cursor clicks? in a Menu's properties to have it ignore the cursor. If you want gameplay-based Menus to be directly-navigated, you have to enable this at runtime using the Engine: Manage systems Action.

    I switch to Mouse Over and back to Player Vicinity when I'm no longer in the close-up sections.

    Is the issue of Hotspots reacting to the cursor occuring when set to Mouse Over or Player Vicinity?

  • Ahhhhhhh -- I think Ignore Cursor Clicks might be the ticket. I just did a quick test and it seems to be getting me the behavior that I'm looking for. I'll set that to "true" on the most offensive menus in my script and see what that does.

    Is the issue of Hotspots reacting to the cursor occuring when set to Mouse Over or Player Vicinity?

    This is an issue in Player Vicinity mode.

  • Yeah man. I think this is working. I'm basically setting these when the game controller is active:

    AC.PlayerMenus.GetMenuWithName ("Interaction").ignoreMouseClicks = true;
    AC.KickStarter.settingsManager.lockCursorOnStart = true;

    Then flipping them back over to false when using mouse/keyboard or in mouse-over hotspot interaction mode.

    Thanks for the guidance...as usual. :)

  • Just a quick update on this. AC.KickStarter.settingsManager.lockCursorOnStart = true; works when switching from mouse/keyboard to game controller in the editor but not in build. Not a big deal though, because the ignoreMouseClicks bit seems to do everything I need. So I've just removed the lockedCursor portion.

  • lockCursorOnStart affects the state of the cursor when the game is booted up - changing it at runtime won't have an effect until the game is restarted.

    To lock the cursor at runtime, call:

    AC.KickStarter.playerInput.SetInGameCursorState (true);
    
  • Got it! Thanks, Chris!

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.