Announcement

Collapse
No announcement yet.

Hold Mouse Button vs. Tap Mouse Button

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

    Hold Mouse Button vs. Tap Mouse Button

    Is there a way that I can have one function tied to tapping the Left Mouse Button, but having a different action occur if the left mouse button is held?

    For example, if a player taps the Left Mouse Button, their character will swing their sword. But if the player holds the mouse button, the character will kick their opponent. I know I could easily just switch that to another button, but I want to know how holding a button will work because it's more practical for the mechanics I have in mind.

    #2
    Originally posted by SirMuttonChops View Post
    Is there a way that I can have one function tied to tapping the Left Mouse Button, but having a different action occur if the left mouse button is held?

    For example, if a player taps the Left Mouse Button, their character will swing their sword. But if the player holds the mouse button, the character will kick their opponent. I know I could easily just switch that to another button, but I want to know how holding a button will work because it's more practical for the mechanics I have in mind.
    Use the release for tap and use press for hold.
    Checkout Project "TwinBlaster" my current game in progress.
    [FREE] - 2D ROPE! Find out more here!
    Forgive my username... It's an old game name and wrote it down as a habit.

    Comment


      #3
      Originally posted by SkeetonYu View Post

      Use the release for tap and use press for hold.
      That doesn't work.

      Comment


        #4
        You will have to time iti think. Once the user presses the mousebutton, set a variable and increas it by delta time, check every frame if accumulated deltatime has reached your desired "hold time", if yes, fire the hold button down action. On button release check if accumulated deltatime is less than desired "hold time", if yes, fire the action user tapped the mouse button. I hope you get the gist of what i mean, sorry if little vague, but thats the only thing i could think of right now.

        Comment


          #5
          Originally posted by SirMuttonChops View Post

          That doesn't work.
          Why wouldn't that work? When pressed make a bool that becomes true.
          Make the bool false when release.

          So now when is pressed make the bool true. Then add a delay. How ever long you want to check. Do a branch. Is the button release? (False) Then do tap logic. If it still true then do hold logic.

          Checkout Project "TwinBlaster" my current game in progress.
          [FREE] - 2D ROPE! Find out more here!
          Forgive my username... It's an old game name and wrote it down as a habit.

          Comment


            #6
            Originally posted by SkeetonYu View Post

            Why wouldn't that work? When pressed make a bool that becomes true.
            Make the bool false when release.

            So now when is pressed make the bool true. Then add a delay. How ever long you want to check. Do a branch. Is the button release? (False) Then do tap logic. If it still true then do hold logic.
            The original reply was splitting the actions to Pressed vs. Released.

            This doesn't work on its own because the "Pressed" Blueprints will try to resolve every time the button is pressed - regardless of whether it's being held or not. So, if a person just taps or holds, that first bit of logic will play out on both occasions. Without any input buffering, it does not allow the Released logic to play out.

            Adding a delay doesn't account for, say, button mashing. If I make the hold for 1 second, an accidental double tap could trigger the hold. And even if it could, it would have to check that time regardless of whether you tap or hold the button because merely pressing it would trigger the check. So, there'd be a delay for any tap attacks added, as well.

            Unreal really needs better input buffering support because the plugin on the Marketplace is not at all intuitive.

            Comment


              #7
              Originally posted by Tiskan View Post
              You will have to time iti think. Once the user presses the mousebutton, set a variable and increas it by delta time, check every frame if accumulated deltatime has reached your desired "hold time", if yes, fire the hold button down action. On button release check if accumulated deltatime is less than desired "hold time", if yes, fire the action user tapped the mouse button. I hope you get the gist of what i mean, sorry if little vague, but thats the only thing i could think of right now.
              I think I understand what you're saying. So pressing creates a variable, X, that tracks the time the button is held. Releasing checks that time - if it is less than X, trigger one set of actions. If it is greater, do the other action. im not 100% sure it'll work, and having to do on-tick events for a combat action in a multiplayer PvP game hopefully doesn't weigh the game down too much... haha

              Comment


                #8
                There is a function called 'get input key time down' it will return the time a key has been pressed. You can then use a float>float comparison to see if the input time is longer than the float threshold, which can drive a branch.

                only thing is that this function will return 0 if you call it on the frame the key is released, so you need to set a float with the input key time down every frame, which is basically the same as adding the deltatime each frame like tiskan mentioned

                Comment

                Working...
                X