Announcement

Collapse
No announcement yet.

Detect which key was used for input (gamepad or keyboard)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Detect which key was used for input (gamepad or keyboard)

    Hello everyone, I am just adding a sprint function to my character. Currently I have it set up so that if the player clicks the left joystick on gamepad, and the current velocity is above a certain amount, it makes the player run. I also would like to add a sprint for the keyboard, so that if the player is holding shift, the player runs, but stops running when they let go of shift.

    The problem is that the input for gamepad should keep running once released, but for keyboard, should stop running when released. Is there any way to tell if it was the keyboard or gamepad that triggered the input?
    Marketplace Assets

    Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
    Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
    Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

    #2
    Just don't attach anything to the gamepad button release event? You could have it click on and click off with just a branch node like this.

    Click image for larger version

Name:	326b46e9442e47943e222599ab6a5195.png
Views:	1
Size:	79.2 KB
ID:	1079630

    Comment


      #3
      Originally posted by Bohrium View Post
      Just don't attach anything to the gamepad button release event? You could have it click on and click off with just a branch node like this.

      [ATTACH=CONFIG]42994[/ATTACH]
      Yes, but I will need to be able to bind other controls to that input, so what else is available?
      Marketplace Assets

      Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
      Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
      Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

      Comment


        #4
        From reading your post, I believe you are asking the following questions:

        1) How do I get the gamepad to keep dashing after the button is pressed?
        This is pretty simple. Do a check to see if the player's velocity is >= a specific amount - 600 for example. If this is true when the player presses the dash input on the gamepad, then switch the the player to a different state called sprinting that changes the character movement's max walk speed to whatever desired new max speed you want. Now, if the player chooses to stop moving then you want to check if the velocity has dropped below a certain point - like 600 again for example - and if true, then you want to switch the player back from the sprinting state to whatever default movement state was being used before. One simple idea for doing the check that comes to mind is using a gate with a tick function that starts off closed, but opens once players have successfully switched to the sprint state.

        2) How do I get the keyboard to dashing only while the dash input is pressed?
        This is easier to do than the gamepad press functionality. All you would do is update it the same way as with the gamepad in pressing the sprint input key should switch the player to the sprinting state, and then once that key is released it should switch right back to the original movement state. However, I can't tell if you are also asking how to make it sprint automatically without holding down an input key for movement on keyboard - like some games have done before.

        3) How can I swap between using both controls seamlessly during runtime?
        This is pretty simple to do. Just use a bool tell which control is being used. For example, when input from the keyboard/mouse is received then mark a bool such as 'KeyboardMode' to true, and set 'GamepadMode' to false. And vice-versa with gamepad input.
        Lastest Developed Games
        Online Portfolio

        Comment


          #5
          Originally posted by Snow901 View Post
          From reading your post, I believe you are asking the following questions:

          1) How do I get the gamepad to keep dashing after the button is pressed?
          This is pretty simple. Do a check to see if the player's velocity is >= a specific amount - 600 for example. If this is true when the player presses the dash input on the gamepad, then switch the the player to a different state called sprinting that changes the character movement's max walk speed to whatever desired new max speed you want. Now, if the player chooses to stop moving then you want to check if the velocity has dropped below a certain point - like 600 again for example - and if true, then you want to switch the player back from the sprinting state to whatever default movement state was being used before. One simple idea for doing the check that comes to mind is using a gate with a tick function that starts off closed, but opens once players have successfully switched to the sprint state.

          2) How do I get the keyboard to dashing only while the dash input is pressed?
          This is easier to do than the gamepad press functionality. All you would do is update it the same way as with the gamepad in pressing the sprint input key should switch the player to the sprinting state, and then once that key is released it should switch right back to the original movement state. However, I can't tell if you are also asking how to make it sprint automatically without holding down an input key for movement on keyboard - like some games have done before.

          3) How can I swap between using both controls seamlessly during runtime?
          This is pretty simple to do. Just use a bool tell which control is being used. For example, when input from the keyboard/mouse is received then mark a bool such as 'KeyboardMode' to true, and set 'GamepadMode' to false. And vice-versa with gamepad input.
          Well, I am already doing #1, and for #2, I have no way to detect whether or not it was a gamepad or keyboard event using just one action mapping.
          Marketplace Assets

          Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
          Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
          Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

          Comment


            #6
            Originally posted by Jamendxman3 View Post
            Well, I am already doing #1, and for #2, I have no way to detect whether or not it was a gamepad or keyboard event using just one action mapping.
            You can make a second action mapping that does the exact same function as another, and assign that to only be fired off by events from gamepad input while the other one only uses keyboard input.
            Lastest Developed Games
            Online Portfolio

            Comment


              #7
              Originally posted by Snow901 View Post
              You can make a second action mapping that does the exact same function as another, and assign that to only be fired off by events from gamepad input while the other one only uses keyboard input.
              Alright, I just figured there may be a way to find input event, but I will do that then.
              Marketplace Assets

              Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
              Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
              Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

              Comment


                #8
                Search "pressed" "held" or "down" something like that. Theres a node that will check if the player is holding a key or had pressed a key in the last frame (two different nodes)
                Tek LLC a personal Candaian Company running BlenderTek & UnrealTek is currently looking for help to bring back submarine simulator gaming with a new genre of sub sims: Cold War! (1945-1991) Operation: Trident SubSim Dev Diary Thread - Donations

                Comment


                  #9
                  I understand that I am writing very late. But it helped me.
                  Attached Files

                  Comment

                  Working...
                  X