Execute recorded movements, detect collision, stop and repeat

Godot Version

Godot 4.2


Hi, I’m struggling with a game where the player records the movements (in an array) and then plays them.
Furthermore, the character (CharacterBody2d) must move straight forward across a tilemap with walls. He only stops when collision ocurs, then, he plays the next movement (left/right/up/down), and so on.

I need help to figure out how to bond all of this. I achieve to store the movements in a list, but I don’t know how to conect player movement (I guess I need CharacterBody2D and move_and_collide/slide, but maybe I’m wrong) with the pre-recorded list and the collision with the tilemap walls (then, the character must stop and await).

Any clue or guide? Thank you!

seems you need a state machine

Thank you, Batiste! This seems to resolve some core problems, and it’s a huge help for me.

Unfortunately, I’m a complete beginner and I still can’t figure out how to move the character straight forward until he collides with a wall of the tilemap. Of course, tilemap and character has collisions configured (nodes, shapes, layers…), but it’s still a mess for me because I try to move character in a parent node script (when I press Enter, execute the movements of the array; this works if I have only one movement and doesn’t take account of collisions), and I don’t know how to move him that direction +1 each frame and stops only when a collision occurs.

And I did’t find any tutorial with this kind of movements. :confused: