Better top down movement

Godot Version

4.3 stable

Question

In my 2d top-down game, I have a character with 8 dir movements. Sprites change depending on the direction of the character’s movement. But I found a problem.

While walking diagonally, you need to release 2 keys to stop, the problem is that if you release one of the keys even for a millisecond later, then the player looks in the direction of the last released key, because of this, it is very difficult to put the player facing diagonally.

How do I fix this?

You can check the elapsed time between the release of both keys.

When one of the keys is released, save the specific time using Time.get_ticks_msec()

Later, when the other key is released, check again the value returned by Time.get_ticks_msec() and compare it to the previous one.

If the difference is not big enough (you should adjust this threshold to your needs), consider it as if the player released both keys at the same time and keep the player facing diagonally

I dont even think about this solution. Thanks a lot))

1 Like