playMaker

Author Topic: Timer depleat on button hold [SOLVED]  (Read 536 times)

Sketch

  • Playmaker Newbie
  • *
  • Posts: 7
Timer depleat on button hold [SOLVED]
« on: May 27, 2021, 04:08:47 PM »
Hello all!

Very new to both Unity and Playmaker. Surprised by just how much I've been able to pull of with literally no experience. Awesome!

Right now I'm trying to implement a kind of hover system in my 2d game. I'm sure it is very common but I can't seem to find advice for it.

The idea is that the player can hover when they hold the shift key. They can press and hold for more lift or tap it for short bursts. That's all working well already. The issue is that I don't want it to be infinite. I want the player to have about 2 seconds of 'fuel' that runs down as they have the key pressed down. After that they have to hit the ground and wait a while before they can go again.

I can't use wait because then it would be 2 seconds from take off regardless of button lift (and every key press would gain 2 seconds...) , I also need the key down on a loop so it can retrigger if they tap before the fuel is spent. The actual hover works perfectly, its just the running out of fuel bit I can't crack.

I've tried using set time with various times (delta, etc) and using variables, it almost works but not quite. The fuel does run out when the timer hits 2, but I have a problem that it only counts as soon as the button is pressed (I think it's time between frames, not real time) so the player can just fly infinity if they hold the key down.

Would anyone have a solution to this? I'm sure it's an easy one as I've seen it done many times before. By the way, I'm using standard unity controls and physics - really just trying to learn the program.
« Last Edit: May 31, 2021, 02:27:39 AM by Sketch »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Timer depleat on button hold
« Reply #1 on: May 28, 2021, 07:37:09 AM »
Hi.
Make a separate fsm 'Fuel handler'

Create a bool "Using Fuel"

Then make a state to add fuel and a state to deduct fuel
Use a float add/subtract and turn on every frame and per second.
This can add / subtract 'fuel'
Also add a bool test on then to check "Using Fuel"
You should also add Float Clamps to limit the value.

On the button fsm :

On the button hold state add a 'Set Fsm Bool' and target the "Using Fuel"
and set to true.

Sketch

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Timer depleat on button hold
« Reply #2 on: May 31, 2021, 02:26:21 AM »
Hi! Sorry for the late reply - long weekend. This seems to have worked well. Thank you so much!