Forum rules - please read before posting.

Toggle between types of gameplay

Hi All,

I'm looking to implement an "inspect room" mechanic in my game (3D third person) in which after pressing a button on the Gamepad, the controls switch from Left joystick controlling player character movement, to instead controlling a cursor on screen that can select hotspots further away from the player. Ideally I'd want to have this button toggle player movement off until it's pressed again, in which if the cursor is pointing over a suitable hotspot, it'll interact with it, and if not, it'll return to regular third person controls.

Additionally, I'd also want this working with keyboard/mouse, where pressing "Tab" for example, would have the same effect, but with the mouse controlling the cursor.

After digging around the scripts within Adventure Creator, would the best way to go about doing this be by messing with MoveUpdate() within the Char script? Or is there a simpler way to disable/switch out player controls?

Appreciate any insight or advice, thanks!

Comments

  • edited August 15

    Welcome to the community, @aM4797.

    You shouldn't need to edit AC's scripts for this, though you may need a custom script to handle some of the finer details.

    Simply preventing the Player from moving, however, can be done with the Player: Constrain Action. This Action also has the option to affect the cursor's locked state. If your intent is for the cursor to be hidden when not in this "inspect room" mode, you could keep the cursor locked by default (as set in the Settings Manager), and then use this Action to unlock and show it.

    To run this Action - and any other you may want - when the player presses an input, use AC's Active Inputs feature in the top toolbar. This lets you run an ActionList when AC detects a given input button has been pressed.

    Then again, are you looking to also change the Hotspot detection method, such that the game uses "Player Vicinity" mode when not in "Inspect room" mode?

    If so, you're best off relying on a custom script so that you can affect this Manager field as part of it. To amend a Manager field at runtime, right-click its label to get an API reference to it.

    There'll be more to it than this, but this first pass script will unlock the cursor, halt player movement, and switch the Hotspot detection method when a given input is pressed:

    using UnityEngine;
    using AC;
    
    public class InspectRoom : MonoBehaviour
    {
    
        public string inputName = "Inspect";
    
        void Update()
        {
            if (!KickStarter.stateHandler.IsInGameplay()) return;
    
            if (KickStarter.playerInput.InputGetButtonDown(inputName))
            {
                bool enterInspectMode = !KickStarter.player.upMovementLocked;
    
                if (enterInspectMode)
                {
                    // Lock player
                    KickStarter.player.upMovementLocked = 
                    KickStarter.player.downMovementLocked = 
                    KickStarter.player.leftMovementLocked = 
                    KickStarter.player.rightMovementLocked = true;
                    KickStarter.player.EndPath();
    
                    // Unlock cursor
                    KickStarter.playerInput.SetInGameCursorState(false);
    
                    // Switch Hotspot detection mode
                    KickStarter.settingsManager.hotspotDetection = HotspotDetection.MouseOver;
                }
                else
                {
                    // Unlock player
                    KickStarter.player.upMovementLocked = 
                    KickStarter.player.downMovementLocked = 
                    KickStarter.player.leftMovementLocked = 
                    KickStarter.player.rightMovementLocked = false;
    
                    // Unlock cursor
                    KickStarter.playerInput.SetInGameCursorState(true);
    
                    // Switch Hotspot detection mode
                    KickStarter.settingsManager.hotspotDetection = HotspotDetection.PlayerVicinity;
                }
            }
        }
    }
    
  • Thank you for the response, it's been insightful. I had a go at both the custom script and also the Active Inputs method, although for some reason I just cannot get it to do anything.

    As you've said, Ideally I'd want to switch Hotspot detection method with this, so custom script would be ideal, but without any luck there I attempted to get Active Input to work:

    I've created a new "control" in the Project Settings Input Manager (Active Input Handling is set to Both), with the Positive Button just being "space". Then I created a new Active Input with the same name for Label & Input Button. I created a new Action List in the "ActionList when trigger" box and have tried a few things (eg. Player Constrain, Setting a Global Variable, Comment, Fade out camera etc.) but regardless it never actually triggers in game.

    Have I overlooked something crucial? I've ensured the Player prefab is assigned in the AC Settings Manager "Player Prefab" and the player loads in all the scenes without issue. I'd appreciate any advice, thank you.

  • Are you using Input System and AC's associated integration Template for regular input handling? I suspect it's a case of this overriding the use of Input Manager.

    If so, try defining the input in the Controls asset it generated within your game's InputSystem subfolder. If the Active Input is then responsive, I expect the script approach will then also be as well.

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.