Hi, so I’ve started to learn how to make snake game in unity today from a toutorial but the code was kind of bewildering especially for me beacuase I’m a begginer at unity and I’m still eleven years old. So here is the code in the toutorial that perplexed me
void Move() {
// Save current position (gap will be here)
Vector2 v = transform.position;
// Move head into new direction (now there is a gap)
transform.Translate(dir);
// Do we have a Tail?
if (tail.Count > 0) {
tail.Last().position = v;
}
so basically what we are doing is we have created the head of the snake and we have also made a list of tales for the snake’s body and the idea is that when the head for the snake moves in a certain direction the last element in the tales list will move to the gap that the head had made; so where the snake’s head was before, but in the toutorial they didn’t say that the last element in the tales list will move to the gap that the snake’s head had made, they said that the last element in the tale’s list will move to the position(transform.position) of the snake’s head not to the gap that the snake’s head had made. so that was confusing beacuse when I ran it what happend was that when the head moved in a certain direction the last element in the snake’s body moved to the gap that the head’s snake had made not to the position of the snake’s head because in the code they said that they will move the last element of the tale’s list to the transform.position of the snake’s head. Do you know why I’m wrong? and do you know why that happens and how it works.
thank you.
And I forgot to say that I called the Move fuction in the start method like this InvokeRepeating("Move", 0.3f,0.3f);
– Ninja7000