How do I check for key pressing frequency?

0 favourites
  • 3 posts
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • i want to manage speed by frequency pressing a key (or a joystick button) as were in the old "olympic games" game (in wich i destroyed several joysticks)

    my idea is to set a speedometer value by the frequency of pressing, i mean fast repeating press key more speed, slower repeating pressing gauge goes down. no pressing gauge returns to 0 speed.

    once got that y may establish the correct speed moving parameters

    thanks in advance.

    i tried with a rotating gauge in certains speed but i only get one frequency than keeps static, if i increase it raises indefinitely, if y slow it comes back to 0.

    poor my english

  • You could try something like this. Speed would be updated per second. You’d just tune the 100 to a speed you’d like. The lerp is to make the change more gradual.

    Global number presses=0
    Global number speed=0
    On key pressed
    — add 1 to presses
    
    Every 1 second
    — set speed to lerp(speed, 100*presses, 0.5)
    — set presses to 0

    Another idea that’s more continuous could be to have an array of say width 60 and

    Global number presses=0
    Global number speed=0
    
    Start of layout
    — array: set size to 60,1,1
    
    Every tick
    — array: set at ticks%60 to 0
    — set presses to 0
    
    Key is down
    Trigger once
    — array: set at ticks%60 to 1
    
    Repeat 60 times
    — add array.at(loopindex) to presses
    
    Every tick
    — set speed to 100*presses
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks, i will try that

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)