How would one make a enemy ai act like a Snake

Godot Version

Godot 4.7

Question

Hello, I’m making a 2d platformer that I want to make some enemies have gimmicks like one that would move like the snake from the game “Snake”

the game I’m making theme is your a little anti Virus creature who eats virus and the enemies would be based on those.

probably is I have no idea how to make the snake work as a enemy with the videos on just the game.

please if you can help me, I really appreciate it.

I am guessing your problem is not movement, but bending.
Imagine it not as a snake, but as lemmings. First Lemming decides where to move: left, up, etc.
Second lemming moves into the position of the first. Third lemming moves into the position of the second. Etc.
Does that make sense?

I believe so, lemming movement sounds pretty difficult to code.

It shouldn’t be harder than anything else.

Each lemming save it’s current position at index =0
var path_history: Array[Vector2] = []
path_history.push_front(global_position)

Each follower reads position at index =1
global_position = target.path_history[index]

There is a bit more code/logic than this, but this is basic idea.

How is your world set up? Is it made out of 2d tiles/blocks (like a pixel sprite) or a “smooth” world like a vector image?

Pixel art, 2d and blocky like.