playMaker

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

BlanketsWilson

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Simple Get Key Down/Up fsm? [SOLVED]
« on: September 27, 2017, 10:56:11 PM »
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 28, 2017, 11:15:51 PM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2260
    • View Profile
    • jinxtergames
Re: Simple Get Key Down/Up fsm?
« Reply #1 on: September 28, 2017, 12: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: 9
    • View Profile
Re: Simple Get Key Down/Up fsm?
« Reply #2 on: September 28, 2017, 06: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?

krmko

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Fat Pug Studio
Re: Simple Get Key Down/Up fsm?
« Reply #3 on: September 28, 2017, 06: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.

BlanketsWilson

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

Thore

  • Playmaker Newbie
  • *
  • Posts: 47
    • View Profile
Re: Simple Get Key Down/Up fsm?
« Reply #5 on: September 28, 2017, 07: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: 9
    • View Profile
Re: Simple Get Key Down/Up fsm?
« Reply #6 on: September 28, 2017, 08: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: 9
    • View Profile
Re: Simple Get Key Down/Up fsm?
« Reply #7 on: September 28, 2017, 08:52:10 PM »
I GOT IT WOOOOOOOO  8) 8) 8)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2260
    • View Profile
    • jinxtergames
Re: Simple Get Key Down/Up fsm? [SOLVED]
« Reply #8 on: September 28, 2017, 11:15:36 PM »
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 :)