Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Snake-like movement

Discussion in 'Editor & General Support' started by Chricken, Jun 2, 2014.

  1. Chricken

    Chricken

    Joined:
    Nov 11, 2013
    Posts:
    13
    Hi people,

    I am asking myself, how to make my snake move.
    All of you may know that little game called snake (http://de.wikipedia.org/wiki/Snake). I am planning this project as my first 2D-project, but I am struggling at the very first basic.

    Does anyone of you have an idea, how I can make the body-objects move along the exactly same track as the head goes.
    I have done a snake before in flash, where I simply put the body-part to the position of the body-part in front of it. But that is not smooth enough in my eyes. So I need to move the objects like a train.

    I hope, someone has an idea.
    Cheers
    Chricken
     
  2. Dave-Hampson

    Dave-Hampson

    Unity Technologies

    Joined:
    Jan 2, 2014
    Posts:
    150

    Maybe move each body part so it is a certain distance away from the one in front?
     
  3. Chricken

    Chricken

    Joined:
    Nov 11, 2013
    Posts:
    13
    Thanks for your idea.
    All physically-based ideas, that I have seen on the web make the body of the snake take some shortcut to follow the head: i.e. http://unitycoder.com/blog/2011/12/05/snake/
    or


    But I need the body parts to move exactly the same way as the head does.
    Just like a train follows the locomotive.

    At the moment, I am thinking about arrays, that contain the former position of the head and make the bodyparts follow it.
    Unfortunately it has to be a very big array :(
     
  4. Chricken

    Chricken

    Joined:
    Nov 11, 2013
    Posts:
    13
    OK,

    tried it in Actionscript (don't have unity at work) and it works fine with arrays.
    Seems like I have to learn, how to use ArrayLists in C# :confused:

    Cheers
    Chricken

    PS: If anyone cares, I have attached the Flash-project.
     

    Attached Files: