playMaker

Author Topic: Press and Release (Tap) Spacebar to Fire Event  (Read 1406 times)

Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • Personal Site
Press and Release (Tap) Spacebar to Fire Event
« on: August 19, 2018, 03:35:36 PM »

I would like to detect when the spacebar is pressed and released (tap of the spacebar), which would then fire a roll. I am also assigning Sprint on the spacebar so not wanting to use GetButtonUp or GetButtonDown for doing the roll. It would simply be a tap of the spacebar, then the player rolls. What action is necessary to do this?


I have tried GetButton, GetButtonDown, GetButtonUp, Get Key, GetKeyDown and GetKeyUp. The Get Button and Get Key works good for storing the result in a variable. The rest works good for detecting when a button is pressed down, or when the button is released, and alternatively storing in variable if needed.


However, I'm not finding a way to detect when a key is pressed and released immediately. So from the idle, run, or sprint the spacebar is tapped (pressed and immediately released), and the player rolls. Any ideas?

nFighter

  • Beta Group
  • Full Member
  • *
  • Posts: 174
    • multiplayer adult fighting
Re: Press and Release (Tap) Spacebar to Fire Event
« Reply #1 on: August 19, 2018, 05:31:32 PM »
Maybe after the KeyDown switch to the state that wait for KeyUp for ~0.3sec and if Key are not going up - it was not a tap so switch to "not a tap" state.
indie developer of multiplayer adult fighting
http://nakedfighter3d.com

Dan

  • Junior Playmaker
  • **
  • Posts: 52
    • Personal Site
Re: Press and Release (Tap) Spacebar to Fire Event
« Reply #2 on: August 20, 2018, 05:31:16 AM »
Good idea. I made an FSM with Get Key Down, Wait at 0.2 seconds, Get Key Up, and Play Animation. I haven't been able to play the animation yet, and not sure why that part isn't working.


But, the spacebar tap works good when viewing the FSM at runtime. I will not know for sure until I can fire the animation but overall it looks good. When holding the spacebar down, it detects as not a tap and returns to listen. When the spacebar is tapped, it fires to the roll state. Thanks for the help  :)