How to make a hold button?

Hey forum, I have a question.
Is there a way to make like a hold button?

I want to press and hold a button so that the more I hold, the higher the jump.
How do I do that?
Do I need to use code to do it?

Thank you again.

You can use it like this:

cont = bge.logic.getCurrentController()
own = cont.owner
jumpF = 0.0
space = cont.sensors["space"] # use the name of the sensor
if space.positive:
    jumpF += 0.1
if jumpF > 0.0 and not space.positive:
    own.setLinearVelocity([0.0, 0.0, jumpF], True)
    jumpF = 0.0

I think so this should work, but I am not sure!

uploading tutorial now 45%

I suggest to you states:

state 1: waiting
state 2: charging
state 3: releasing

waiting: pressing the hold button -> charging
charging: releasing the hold button -> releasing
releasing: done -> waiting


  • nothing


  • frequently increment charge (property add)


  • consume the charge (read the property, set charge to zero or reduce by used amount)
  • use the consumed value

Here is a demo:

including charge limits and charge display (see BGE Guide to Messages incl. Healthbar tutorial)


ChargeDemo.blend (630 KB)