Forum rules - please read before posting.

Having "E" as the interaction key instead of left mouse click

Hi, I'm working on a FPS game where there will be combat. Therefore, I'd like the left mouse click to be used to shoot weapons by default, and the E key to handle the AC interactions with the world. How would I go about making such a change?

Comments

  • edited August 2023

    Could you try this:
    I think you could get the wanted behaviour by unchecking "Mouse clicks have default functionality?" in AC Editor -> Settings -> Interface Settings, one under "Input Method:".

    And then you go into your Project Settings -> Input Manager, and set up a new Input called "InteractionA" and set the positive Button to "e".

  • Great, thank you, will try this.

  • edited August 2023

    I tried this, but then doing so has the effect that even clicking options on a menu require to press the "E" key (instead of the left mouse button)

    The behaviour I'm trying to achieve is this:
    1. When in-game, clicking left mouse button fires a weapon. And pressing 'e' interacts with Hotspots etc.
    2. When the game is paused or on a menu or in a cut scene, the left mouse button acts as the regular mouse cursor, at which point, left click would behave as a regular left click and interact with the UI.

    Thanks in advance for any insights on how to achieve this. Thank you.

  • edited August 2023

    Hmm... I had a look at the combat example project. This code looks promising:

    if (KickStarter.stateHandler.IsInGameplay ())
    {
    if (CanAttack ())
    {
    // Recieve aim/fire input if in gameplay and a weapon is equipped

    SetAimState (Input.GetButton ("Aim"));

    if (IsAiming ())
    {
    if (Input.GetButtonDown ("Fire1"))
    {
    Attack ();

    // Prevent Interaction input from being received in the same frame as firing a weapon (so that the two cannot occur simultaneously)
    KickStarter.playerInteraction.IgnoreInputThisFrame ();
    }
    else if (Input.GetButtonDown ("Reload"))
    {
    Reload (heldWeaponInstance);

    I further studied the FP_Crouch script that comes with the downloadable First Person controller for AC. I think I might be able to make a copy of that and then use the above script as an FP_Shoot script

    Would this be the right approach?

  • edited August 2023

    I've set it up again and i can't recreate the issue that you have.

    https://streamable.com/bp2t5u

    I have the FPS Player and if i set it up like this it does work how you intended, mouseclicks don't activate the hotspot, only "e" does, and when i press escape or use a Menu, the mouseclicks work how they should.

    The "pause game when enabled" option on the affected menu, should automatically pause the game and unlock the mouse.

    Chris can probably help out, i wasn't able to get the same problem :neutral:

  • edited August 2023

    Hi Snan, thank you for checking back; I did try it again, but I'm facing the same issue. If I go to the Input Manager and map InteractionA to the "e" key, then in all the menus, I have to press "e" instead of left mouseclick to select a menu item. And mouse clicks don't do anything. Not sure what might be working differently for me, but thank you for trying to help. Let me keep checking.

    Meanwhile, @ChrisIceBox please let me know if I'm doing anything wrong.

  • edited August 2023

    Did by chance the Mouse Button Interaction somehow get screwed up/replaced in the Input Settings?
    Maybe i'm overlooking something. Hope you can get it figured out.

    //
    I did it in a completely new empty Project, too.

    1. Imported the newest AC-Version.
    2. Imported the PLAYER PREFAB: FIRST-PERSON from the Download Section https://adventurecreator.org/downloads.
    3. Open Project Settings -> Player Input.
    4. Set the CursorHorizontal & CursorVertical for the X,Y Axis Mouse Movement.
    5. Added "InteractionA" and set its positive Button to "e".
    6. Disabled "Mouse clicks have default functionality" in the Interface Settings.
    7. Created a Box and put a Hotspot on it, that plays a sound when used.

    And everything works as intended, that is very confusing.

  • Hey Snan, I started a new empty unity project, added AC into it, and then unchecked "Mouse clicks have default functionality?" and as expected mouse clicks don't work on the menu nor interact with hotspots.

    Then I added InteractionA in Input Manager and mapped it to "e" and now pressing "e" works for both interactions and to select a menu item. But mouse clicks don't work at all in the menus.

    Not sure what I'm doing wrong. I will keep trying, thank you for your help.

  • I found the solution here:
    https://www.adventurecreator.org/forum/discussion/9331/button-press-to-pickup-item

    It seems another user had the same problem; if he disabled "Mouse clicks have default functionality?" then the menus stopped responding to mouseclicks.

    Instead, he changed "Interaction Method" to "Choose Interaction then hotspot" which gives three new input actions for the Input Manager. And you can map custom keys to "use", "examine" etc.

    Thank you for the suggestions and help.

  • edited August 2023

    Ok, the above method didn't fully work so I finally solved it as follows:
    1. Set "Settings > Interface Settings > Interaction Method" to "Custom Script"
    2. Keep "Mouse Clicks have Default functionality" as checked (so menus will work)
    3. Created the below script for a custom interaction:

    using UnityEngine;
    namespace AC
    {

    [AddComponentMenu("Adventure Creator/3rd-party/Custom interaction system example")]
    [HelpURL("https://www.adventurecreator.org/scripting-guide/class_a_c_1_1_custom_interaction_system_example.html")]
    public class UseEInteraction : MonoBehaviour
    {
    
        private Hotspot selectedHotspot = null;
        private bool isLookingAtHotSpot = false;
    
        private void OnEnable ()
        {
            EventManager.OnHotspotSelect += OnHotSpotSelected;
            EventManager.OnHotspotDeselect += OnHotSpotDeSelected;
            //EventManager.OnStartSpeech += OnSpeechStarted;
            //EventManager.OnStopSpeech  += OnSpeechStopped;
        }
    
        private void OnDisable ()
        {
            EventManager.OnHotspotSelect -= OnHotSpotSelected;
            EventManager.OnHotspotDeselect -= OnHotSpotDeSelected;
            //EventManager.OnStartSpeech -= OnSpeechStarted;
            //EventManager.OnStopSpeech  -= OnSpeechStopped;        
        }
    
        private void Start ()
        {
            if (KickStarter.settingsManager != null && KickStarter.settingsManager.interactionMethod != AC_InteractionMethod.CustomScript)
            {
                ACDebug.LogWarning ("This script works best when the Settings Manager's 'Interaction method' field is set to 'Custom Script'.", this);
            }
        }
    
        private void Update ()
        {
            if (KickStarter.stateHandler.gameState != GameState.Normal)
            {
                return;
            }
    
            if (isLookingAtHotSpot) {
                if (KickStarter.playerInput.InputGetButtonDown ("ActivateHotspot")) {
                    ACDebug.LogWarning ("Pressed E.", this);
                    selectedHotspot.RunUseInteraction ();
                }   
            }
        }
    
        private void OnHotSpotSelected (Hotspot hotspot)
        {
           isLookingAtHotSpot = true;
           selectedHotspot = hotspot;
        }
    
    
        private void OnHotSpotDeSelected (Hotspot hotspot)
        {
           isLookingAtHotSpot = false;
           selectedHotspot = null;
        }
    }
    

    }

    1. Add this script to a game object
    2. Add a new key in InputManager called "ActivateHotspot" and assign it any key.

    This works for me because I'm making a very simple combat based game where there is only one interaction with any hotspot. I needed a very simple solution and this seems to be working so far.

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.