Snake game, problem with tail
Hi, Everyone! I trying to make snake game with this tutorial, but with few changes. I want to make moving more smooth, so i move 'Move Function' to Update. But now when snake eat food, tail spawn in/on snake (look picture - white block is head, red block is tail). I understand, thats cos current position saving bit to fast. So how i can fix it? Here's code of 'Move' func:
void Move()
{
Vector2 v = transform.position;
transform.Translate(dir * speed * Time.deltaTime);
if (ate)
{
GameObject g = (GameObject)Instantiate(tailPrefab, v, Quaternion.identity);
tail.Insert(0, g.transform);
ate = false;
}
else if (tail.Count > 0)
{
tail.Last().position = v;
tail.Insert(0, tail.Last());
tail.RemoveAt(tail.Count - 1);
}
}
screenshot-1.png
(4.8 kB)
Comment