I am working at a 2D Snake Game in Unity. This is the head of the Snake: https://i.stack.imgur.com/MeelN.png And this is the Extension of the tail of the snake. It is added everytime I eat something: https://i.stack.imgur.com/IoagT.png I made the head of the snake to move, but my question is how do I move the extensions? I tried to add these extensions as childs to the head , but when i rotate the head, it rotates the all extensions at the same time, but I want to rotate one extension at a time like a chain. I am using a C# Script

if (position == 1 || position == 3) {
            if (Input.GetKey (KeyCode.UpArrow)) {
                position = 2;

            } else if (Input.GetKey (KeyCode.DownArrow)) {
                position = 4;
                transform.rotation=Quaternion.Euler (0,0,rotation);
        } else if (position == 2 || position == 4) {
                transform.rotation=Quaternion.Euler (0,0,rotation);
            else if(Input.GetKey(KeyCode.LeftArrow)){
                transform.rotation=Quaternion.Euler (0,0,rotation);
        if (position == 1)
            transform.Translate (Vector3.right * movementSpeed * Time.deltaTime,Space.World);
        else if (position == 2)
            transform.Translate (Vector3.up* movementSpeed * Time.deltaTime,Space.World);
        else if(position==3)
        else if(position==4)
            transform.Translate (Vector3.down*movementSpeed*Time.deltaTime,Space.World);
        int i;
        for (i=1; i<extensions.Count; i++) {
  • \$\begingroup\$ I think it would be best to create some form of path for each piece to follow, as in wherever the head goes, the other parts would follow a step away. That would include rotation and transformation of course. \$\endgroup\$
    – Cold999
    Sep 20, 2015 at 9:56
  • \$\begingroup\$ Have you seen this question/answer? It covers what you want, even though it's not specific to Unity. \$\endgroup\$
    – House
    Sep 20, 2015 at 15:08

1 Answer 1


In unity, you will want to child all the segments (including the head) to an empty GameObject. Then you can move/rotate each child peice, including the head.

The way it works in the classic game is that only the head actually moves. The tail piece is removed from the end and a new segment is added where the head was last time. So only two segments are being moved each frame (head and tail). Not all segments.

1. Move the head one space
2. Remove the tail piece
3. Fill in the space where the head was, with a new body/tail segment. Since you are removing the tail segment, you can reuse that GameObject for the new (neck) segment. Unless of course if you are using a unique segment for the tail piece. Then you would need to move 3 segments each frame.

  • \$\begingroup\$ Yeah, but how do I know when to rotate the specific segment? \$\endgroup\$
    – Bogdan15
    Sep 20, 2015 at 14:26
  • \$\begingroup\$ If you do like I described, only the head rotates. The body doesn't actually move. You just remove from the back and add to the front. \$\endgroup\$ Sep 20, 2015 at 15:31
  • \$\begingroup\$ But these sprites are not the 70's squares. My extension is not a square, is a rectangle and if I only remove it and add it to the front it will have the same rotation and it will look different if my head is going up for example \$\endgroup\$
    – Bogdan15
    Sep 20, 2015 at 16:10
  • \$\begingroup\$ @Bogdan15 Move the piece as described in the answer. Since you're only moving one segment, and it's always where the head was, use the rotation of the head from the last update. Alternatively, rotate it to point towards the head. \$\endgroup\$
    – House
    Sep 20, 2015 at 17:25
  • \$\begingroup\$ @Bogdan15 I think I understand what you mean but it's unclear how you want your snake to bend. IE. Does it turn 90 degrees each time or any angle? Please post a picture of what you want your snake to look like during the game with some bends. Either way, you can still do the actual movement like I described. How to rotate it so your snake doesn't look like it has a broken back is a different problem. \$\endgroup\$ Sep 20, 2015 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .