I need help about how to implement movement like snake game

I can’t figure out how to do snake movement pattern where there are:

  1. Head it’s the main part when you press WASD it moves normally (This part is done)
  2. The body of snake containing multiple parts for my game it isn’t really a snake but it’s a group of characters following the previous character movement without going to collapse the position of the previous character
    It looks something like the picture above, assume that the top most blue hat guy is the head and the bodies move according to where the head has moved in straight line
    how to do action like Body 1 move follow head, Body 2 move follow body 1, Body 3 move follow body 2 etc.

Please help me, Thank you in advance.

Note: this goes on a bit but I hope some of it is useful.

How close to the original snake game are you going for? Is this a grid based like movement or more fluid? I only know the original. A smoother version would be more complex and I’m not sure of how that would work. Maybe a mix of the original with tweens. IDK.

The original game is actually pretty easy. When the head moves it adds a new segment where the head is, it then moves the head by the grid size and deletes the last block. You can track the blocks by using an object ID variable with 2 counters. I variable for the ID of the last block and another for the ID of the next block.

Now that I’m thinking about it. It would be better to move the last block to the head position and change it’s ID number instead of adding and deleting.

Since you use different animations then you could use a repeat with a counter. Then go through and using another variable change the animation to the animation of the next ID.

Say there were 5 body segments. The IDs would be 1 thru 5 with 1 being the last segment. You move the one with an ID of 1 to where the head is and change it’s ID to the next ID which would be 6. You then move the head. You could then shift the animations. I’m not at my PC. That would be with a few variables. One for the counter and then variables for an old and new animation name or number. I can’t really put it into words without testing it. Something like newAnim equals animation, animation equals equal oldAnim then oldAnim equals newAnim sort of like a buffer. IDK if that makes sense.

For fluid movement. IDK. I’m guessing tweens and/or distance checks. Going straight would be easy but square corners would be tougher unless each one tweened to the position of the one ahead of it. That would only work with a grid like movement.

1 Like

Hi, Thank you for the advice, my game is not the traditional snake game however I found a way to do that with extension but I have some minor problem

I use this extension it meets my requirement about 90% except it can collide with others (but it’s fine)

It creates clone that move according to the main object so I recreate the clone for x times and make it follows the previous object, BUT I have some problem

The above event works fine except it is not dynamically work

The extension doesn’t allow me to use expression it only allows the object name to be input
Do you know how to modify the extension to accept expression? I have 0 experience about modifying extensions.

I just want the extension to create clones according to my array list for example now I have size of snake of 5 so there will be creating what ever is on that array index 5 which follows whatever on the previous array index 4 like this Create Party.MemberList[Counter] that follows Party.MemberList[Counter -1]

This is what I see on the editor

Extensions cant create objects by its name. Unless you use javascript on it.

1 Like

Ohh, could you please give me some example of how to do that or any document?


const myObj = runtimeScene.createObject(eventsFunctionContext.getArgument(“ObjectName”));

I don’t know the extension. It might be easier to make the extension change the animation instead of adding Javascript to pick the object. You could add a few parameters, there’s even an animation name parameter type and then change the animation.