Playmaker Forum

Playmaker Help & Tips => Playmaker Help => Topic started by: BlanketsWilson on September 27, 2017, 10:56:11 PM

Title: Simple Get Key Down/Up fsm? [SOLVED]
Post by: BlanketsWilson 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!
Title: Re: Simple Get Key Down/Up fsm?
Post by: djaydino 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.
Title: Re: Simple Get Key Down/Up fsm?
Post by: BlanketsWilson 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?
Title: Re: Simple Get Key Down/Up fsm?
Post by: krmko 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.
Title: Re: Simple Get Key Down/Up fsm?
Post by: BlanketsWilson on September 28, 2017, 06:11:30 PM
I still cannot get this to work!!!  :'( :'( :'( :'(
Title: Re: Simple Get Key Down/Up fsm?
Post by: Thore 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 (https://docs.unity3d.com/Manual/class-InputManager.html). 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.



Title: Re: Simple Get Key Down/Up fsm?
Post by: BlanketsWilson 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 (https://docs.unity3d.com/Manual/class-InputManager.html). 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.
Title: Re: Simple Get Key Down/Up fsm?
Post by: BlanketsWilson on September 28, 2017, 08:52:10 PM
I GOT IT WOOOOOOOO  8) 8) 8)
Title: Re: Simple Get Key Down/Up fsm? [SOLVED]
Post by: djaydino 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 (https://hutonggames.fogbugz.com/default.asp?W548) to get more familiar with playmaker :)