No announcement yet.

Usining multiple "Key-Maps"

  • Filter
  • Time
  • Show
Clear All
new posts

    Usining multiple "Key-Maps"

    Hey there!
    This is my first post.
    I recently downloaded UE4 to play around with it.
    I'm coming from XNA, LibGDX, MonoGame in which I learned the basics, but to go further, I wanted to use something to handle the low-level
    stuff to give me more time to focus on the Game-Design, Gameplay etc.

    I decided to start with a little game using a Controller (Xbox or PS) in which the controls change.
    What I mean is, there are different game-modes (and with game-mode I mean, that they need different Key-Maps):

    Conversation with NPC

    The 4 Action keys for Normal might be:
    Attack to enter Battle

    When Facing to a NPC and standing in a specific range, the Attack-Button should change to TalkTo button.

    In Battle the 4 Action-Buttons should be mapped to different attacks, depending on how the player bound the attacks to the buttons.

    In conversation there are only two buttons active (player movement is inactive) in which the player can press
    Continue/Accept or Cancel while the axis controlles the different choises.

    My attempt is (in order to not use static patterns) is to use something like Events.
    When an Event occures (for example the NPC is in range and the Player looks at it) it changes
    the keys to the desired actions. On leave it changes back.

    When in Menu Player-Controll should be inactive and only the Menu can be controlled and that time.
    Here I wanted to give every Menu-Choise an Event which is activated when the Choise is selected and the player press the Accept-Button, while the
    Back-Button goes to the higher Menu-Level. The Close-Button will close the Menu and return to the game.

    I do not want to use different Levels as I want to use the same behaviour to a muliplayer-version and it would look kinda funny if
    a Player disappears if he enters the menu.

    So my question is: Is there any other way to accomplish this tasks which might be a more elegant solution (for example, I just saw a blueprint called widget)?

    And sorry for my bad english. It's not my mother tongue.

    Thank you!

    No one can help me?


      Maybe I just explained my problem wrong :/.
      My problem is, that I need to know if there is an easy way to make buttons on a (let's say Xbox-) Controller have different functions in different situations.

      For example:
      X means Jump when just moving in a normal state.
      But when entering a specific area X means TalkTo (or Continue or anyting else)

      This should be working for every button.

      Is there an easy way? Or do I have to hardcode it?
      Like a Global switch:
      like "If Mode = XYZ -> X do this, Y do that" etc.?


        Use Branches and variables to determine what the buttons should be doing. So right off of the Event Input X for example, determine if character is moving, if true then jump. If false, check if in proximity to NPC to TalkTo, if true then talk. Etc, etc...


          You can binding one key to many actions and filtering it with Branch node.

          Click image for larger version

Name:	action_bind.PNG
Views:	1
Size:	306.3 KB
ID:	1080345


            Well I suppose the first question is: do you want the player to be able to remap these command sets independently?

            For example, Just Cause 2 has multiple key configs; you can independently change what keys do on foot, when driving, when flying, etc.

            Do you want the player to be flipped between "combat" and "interaction" control sets such that he could either bind the talk command to the key that makes him Jump in combat, OR the key that makes him Block in combat, OR the key that makes him swing in combat?

            Or do you just want the jump button to do something other than make the player jump in certain circumstances?

            If it's the latter, it's almost trivially easy. Create a new Enum type, call it "control state", say. Add some entries for it; Default, Interaction, Combat, whatever. You can always add more later.

            Add a variable of the type ControlState to your CharacterBP. What you will do is Set this variable's value in response to the external state of the level; e.g. when the player enters the NPC interact overlap, Set ControlState to Interact. When an enemy is in range, Set ControlState to combat.

            Now, from EACH InputAction, hit a SwitchOnControlState node and connect it to this variable. So the Jump Key will hit this node and if the control state is either Default or Combat, it will move out those execution paths to the jumping function. If it's set to Interaction, it will then instead go out the Interaction path to whatever logic you use for triggering NPC dialog.


              Ah, well, thank you for your answer!

              There are two Types of Controls.
              The general movement
              and the battle movement.

              The general movement should not be settable by the player.
              As I said the problem here was that one key on the controller could have many functions.
              Like Jumping in one situation where the character can roam free and talking to an NPC when targeting one and being near to it.

              The battle movement is quite a bit different.
              In battle there are the Attack-Buttons (for xBox it is X Y A B)
              and the Sticks & Shoulder-Pads.
              Stick and Shoulder-Pads are not settable and will always have the same function in battle.
              The Attack-Buttons though can be changed by the player in the inventory-menu.

              The player can collect and envolve attacks (like items) and assign them to the buttons.


                Oh okay, if you're gonna hard-code the player to a single controller config then yeah, just do what I described above.
                Make an Enum variable called "Control State", and add two entries to it: General and Battle (this way you can still add more later... Maybe for menu navigation, for instance...)

                In the Character BP, creae a variable of the ControlState Enum type, call it "current control" or whatever.

                Then from each InputAction Press and/or Release path, hit a Switch On ControlState node, with the enum pin connected to the CurrentControl variable. The execution path for that button will then be forked based on the current value of CurrentControl.

                So in battle, you'd Set CurrentControl on your player to have the value "battle". When he presses jump, the Switch On node will route the execution flow out the Battle pin, to the logic which makes him jump. When the battle ends, you'd Set CurrentControl to have the value "general", and the execution from Jump wll flow out the General pin, to the logic which triggers interaction with surroundings.

                If you have one single button which is like a really multipurpose "Action Button", ie it opens doors, climbs ladders, talks to NPCs, flips switches, and a jillion other contextual things, it would probably be best to create an Interface Blueprint (these let you blindly fire messages out to other BPs without knowing their class), and add a single blank "TriggerInteract" function to it.

                So what you'd do is, you'd use your overlap or line trace or whatever to find the player's current Context Target. Set this to some Actor variable on your Character (say, CurrentInteractTarget). The general purpose interact button would, on the execution path for general rather than battle, Get CurrentInteractTarget, and call on it the Interface Message "TriggerInteract".

                Then, for any interactable actor, you'd implement the Interface, and implement "Event TriggerInteract". This way, what happens is the player walks into range of some object. By so doing, he creates a reference to that object as the CurrentInteractTarget variable. When he hits the interact key, he sends a message to whatever actor it is "you are interacted with". Then that specific actor can implement its own logic for what to do when the player interacts with it (if it's a chest, it opens. If it's an NPC, it triggers a dialogue bubble. If it's a shopkeeper, it brings up the shop menu. Whatever)


                  Okay, thank you for your help.
                  I think there is a little misunderstanding about the battlemode.
                  In roaming this is quite easy, as it is (like you mentioned) hard-coded controlls.
                  Just to give you a little Image of what the Controls are like in different situations (let the axis be no concern atm).
                  First of all the non-Battle-Controlls

                  A - Jump
                  X - Interact/Attack a Monster on open field
                  Y - Map
                  B - Inventory

                  A - Accept
                  X - Nothing
                  Y - When in Item-List -> Sort
                  B - Back

                  Talking to NPCs
                  A - Accept / Continue
                  X - Nothing
                  Y - Nothing
                  B - Cancel

                  Okay now in Battle it is nothing like that.
                  In-Game Players can collect Attacks like Items.
                  For example -
                  A player opens a Chest and he finds -> Quick Attack
                  The player can level this Quick Attack to get stronger and Envolve it to something like -> Quick Slash

                  So the Battle-Controlls are configurable via the Menu.
                  A Player places these "Items" on the Button-Slots

                  Quick example:
                  The player has : Fire, Ice, Lighting, Attack, Quick Attack, Heavy Attack
                  He chooses

                  A - Attack
                  B - Quick Attack
                  X - Ice
                  Y - Lighting

                  (Well in the actual game, there are many configurable patters which can be exchangend while in battle)

                  So the Game needs to get the configured List of Attacks from a file (and save them to a file) to know which attacks are setted to which button.

                  Second problem is the Menu.
                  Is there some Widged ore something, or do I need to give every button its own event and hardcode something like:

                  If (player clicks Down) -> Button_Selected[x] = False; Button_Selected[x+1] = true
                  If (Player clikcs A) -> Button[x].getAction;

                  I think its gonna be huge work to give every MenuEntry this kind of work as every of these Entries could lead to a different
                  menu-part :/
                  Last edited by JustJim; 06-30-2015, 05:18 AM.