playMaker

Author Topic: Simple Get Key Down/Up fsm? [SOLVED]  (Read 6980 times)

BlanketsWilson

  • Playmaker Newbie
  • *
  • Posts: 13
Simple Get Key Down/Up fsm? [SOLVED]
« on: September 28, 2017, 01:56:11 AM »
There has to be a simple solution for this.

I want, when the user presses the A key, a model in the game is pressed down at the same time, and is held there until the A key is released, and then the model will go back to its original position.

Basically trying to mimic an actual keyboard.

Thanks!
« Last Edit: September 29, 2017, 02:15:51 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Simple Get Key Down/Up fsm?
« Reply #1 on: September 28, 2017, 03:51:02 AM »
Hi,
You can use 'Get Key Down' and Get Key Up'

if you want multiple  letters to work at the same time you need to use an fsm for each letter.

BlanketsWilson

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Simple Get Key Down/Up fsm?
« Reply #2 on: September 28, 2017, 09:02:11 AM »
Yeah, but how will the key actually go down, and stay there?

Are they being animated? Are there multiple animations, one for going down, and one coming back up?

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Simple Get Key Down/Up fsm?
« Reply #3 on: September 28, 2017, 09:15:43 AM »
I would make an FSM for every key, as Djaydino said. You can move them and limit the movement of the model by using two colliders (one for pressed position and one for released position), you don't have to animate them.
Available for Playmaker work

BlanketsWilson

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Simple Get Key Down/Up fsm?
« Reply #4 on: September 28, 2017, 09:11:30 PM »
I still cannot get this to work!!!  :'( :'( :'( :'(

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Simple Get Key Down/Up fsm?
« Reply #5 on: September 28, 2017, 10:30:27 PM »
Hi,

Try this. Make two events called pressed and released.
State 1, Press A: get key down, A key, goes to pressed event.

State 2, Release A: get key up, goes back to state 1. Not sure, but check also key pressed, if false then also go back to state 1.

1) First watch the FSM. Does it go to the proper state when you press A and release?

2) Now, you can animate the key with a usual animation clip. The is also the new timeline feature. You can move it by smooth transform, with actions like move towards, itween move etc. As a tip, use two empty invisible GameObjects, give them a gizmo icon (inspector top left when selected) to mark the two positions, then your thing can move towards one and back to the other, advantage you can easily tweak the positions by moving your start/end points around. You can also note down the vector (start/end position) and set this in variables. And finally, you can move stuff with physics, add velocity, add force, change gravity etc.

3) Once more, be aware of Input Manager. Same principle, but you use Get Button etc instead of key, and you assign the keys/inputs to your buttons in the manager. Depends on what you try to do, as always. If you have only keyboard, and it is straight forward, go ahead with keys. If you have other inputs, alternative layouts etc, use Buttons.




BlanketsWilson

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Simple Get Key Down/Up fsm?
« Reply #6 on: September 28, 2017, 11:23:55 PM »
Thanks for the advice, I got Press A/Release A, communicating and holding as I hold the key down like I want. But I can't get anything to move! I tried the move towards action as well as animating.

Hi,

Try this. Make two events called pressed and released.
State 1, Press A: get key down, A key, goes to pressed event.

State 2, Release A: get key up, goes back to state 1. Not sure, but check also key pressed, if false then also go back to state 1.

1) First watch the FSM. Does it go to the proper state when you press A and release?

2) Now, you can animate the key with a usual animation clip. The is also the new timeline feature. You can move it by smooth transform, with actions like move towards, itween move etc. As a tip, use two empty invisible GameObjects, give them a gizmo icon (inspector top left when selected) to mark the two positions, then your thing can move towards one and back to the other, advantage you can easily tweak the positions by moving your start/end points around. You can also note down the vector (start/end position) and set this in variables. And finally, you can move stuff with physics, add velocity, add force, change gravity etc.

3) Once more, be aware of Input Manager. Same principle, but you use Get Button etc instead of key, and you assign the keys/inputs to your buttons in the manager. Depends on what you try to do, as always. If you have only keyboard, and it is straight forward, go ahead with keys. If you have other inputs, alternative layouts etc, use Buttons.

BlanketsWilson

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Simple Get Key Down/Up fsm?
« Reply #7 on: September 28, 2017, 11:52:10 PM »
I GOT IT WOOOOOOOO  8) 8) 8)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Simple Get Key Down/Up fsm? [SOLVED]
« Reply #8 on: September 29, 2017, 02:15:36 AM »
Hi,
I am happy you got it to work,

You can find several tutorials on the user tutorial wiki page to get more familiar with playmaker :)