Detect how much the player has walked?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Kenbo

Looking for ideas to (title). Could just increase a variable when a key is pressed but I feel like that could vary with different framerates. Maybe I should do a timer?

Fyi I am making a 2d platformer.


:bust_in_silhouette: Reply From: al3x

you can probably do the following in a script or smtg

if up,down,left or right key is being held
wait a few milliseconds
increase the variable of steps by 1

So like this should work?

if Input.is_action_pressed("right"):
    steps += 1

Kenbo | 2022-04-11 22:32