Release keys at the same time without requiring frame perfect

Godot Version

v4.3.stable.official [77dcf97d8]

Question

Player top-down character has 8-dir animation. And idle has also 8 directions. Direction is saved with this code:

dir = Input.get_vector("go_left", "go_right", "go_up", "go_down").round()
if dir: #save direction
	idle_dir = dir

And when player goes diagonally and releases one key few frames earlier from other idle animation is 4-directional. I can use timers, but is there is a good way to do this?

You could store the idle directions from the last ~5 frames in an array and average that when the player finally stops :thinking: It reminds me of input buffering, maybe look into that technique

Timers are actually pretty nice, because they are framerate independent. So if someone runs your game at 30fps or 120fps it behaves the same with no extra work.

1 Like