playMaker

Author Topic: key down / count / key up  (Read 2035 times)

jorseoncode

  • Playmaker Newbie
  • *
  • Posts: 3
key down / count / key up
« on: April 26, 2020, 03:45:51 AM »
Hi,

having a problem making a FSM. I want to make an object jump high depending on how long you hold your key down.

tried to make it with add int value on every frame and store it as variable, but it stops counting like in a second all tho the key is still pressed. here is a gif.

https://gfycat.com/jealousdefenselesslamprey

whats wrong with this or any better solution?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: key down / count / key up
« Reply #1 on: April 26, 2020, 09:33:35 AM »
Hi.
you should use a wait :

State 1 :
get key down.

State 2 :
Add force (for jump, this can be different for you)
Wait (Set maximum hold time)
Get Key Up :

'Get Key UP' and 'Wait' can both Transition to the same next state.

So as long als player hold they key it will not change until wait has ended OR player released key

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: key down / count / key up
« Reply #2 on: January 28, 2021, 11:51:42 AM »
Sorry for bumping an older post, but I have a question. I tried to follow this, but it would not work. Could you perhaps give a more detailed explanation or an alternative solution. I think I'm following everything correctly. Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: key down / count / key up
« Reply #3 on: January 28, 2021, 04:02:35 PM »
Hi.
Try a setup with a simple box (with a rigidbody(2D) and only make a jump fsms.
 and see if that works.

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: key down / count / key up
« Reply #4 on: January 28, 2021, 05:10:15 PM »
Tried what you said and still didn't work. Here's the FSM, if that will help. Thanks again!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: key down / count / key up
« Reply #5 on: January 29, 2021, 05:01:25 AM »
Hi.
You need to turn on 'Every Frame' on 'Add Force'

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: key down / count / key up
« Reply #6 on: January 29, 2021, 03:02:58 PM »
It just seems to launch my character really high in the air or won't jump at all (no in between) depending on how I set the numbers. Also, it makes my game lag really bad. Now granted, I'm using a slightly different set up in my real game where the jump height is changed depending on how many collectibles are grabbed, but that shouldn't make a difference, right?

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: key down / count / key up
« Reply #7 on: January 29, 2021, 10:37:34 PM »
Ok, so I mostly figured it out with some tweaking. Only one slight problem remains. He sometimes jumps higher than others despite if I hold down the jump key for the same amount of time. I'm using a set up where I have a collectible and when the player touches it, it adds wait time and jump height to the FSM. Not sure if that would make a difference. Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: key down / count / key up
« Reply #8 on: January 30, 2021, 10:39:38 AM »
hi.
Force is using physics and gravity, mass etc. and is not reliable to have the same height every time.

You can try using velocity. but it has other disadvantages.

misterjuly

  • Sr. Member
  • ****
  • Posts: 334
Re: key down / count / key up
« Reply #9 on: January 30, 2021, 10:52:41 AM »
Worked! Thanks!