Topic was automatically imported from the old Question2Answer platform.
Asked By
alibix
Old Version
Published before Godot 3 was released.
So I’ve tried to make a platforming finite state machine.
It has 2 states:
idle
walking
And two transitions:
onMovementPressed
onMovementReleased
This is what it looks like with the awesome FSM plugin by Jakub Grzesik.
The character will transition from idle to walking if the left or right button is pressed. Using this code:
(the face left and face right are just to change the way the character is facing)
The character will transition back to idle if the left or right button is stopped being pressed:
(the transitions will happen if the transition function returns true)
This system works… okay. However, it is quite bad for quick movements. If I press left and right really quickly the character gets stuck in place or moonwalks in one direction (without turning around). Is there a better way to transition between these states that is snappy and glitch free?
If does not respond well to quick movements is because you never blocked/ignored the inputs while is moving.
Some extra check you may want are the release and press/pressed events when is too close to the landing point to stop,continue or reset movement (_input/_input_event could be better for this kind of mechanics).
Thank you! Also, I changed my player to be kinematic instead of rigid body. That made things a lot snappier.
alibix | 2017-06-26 22:03
In general, rigid bodies are not good unless you designed your game to respect the physics engine craziness, and generic physics engines don’t like grid or similar mechanics too much.
There is the custom integrator on Godot rigidbodies that allow more fine control but if you are not going to use rigid physics is better to avoid them.