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.

Thanks

: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"):
	yield(get_tree().create_timer(0.03),"timeout")
    steps += 1

Kenbo | 2022-04-11 22:32