- Home /
Can Invoke("Restart") unsynchronize the animation?
I'm making game similar to classic snake game. My snake is moving on grid. The snake itself is broken into pieces, this pieces got animations. When part of the snake moves to the next grid, the animation of this part should start all over again. Move of snake is implemented in function induced with:
InvokeRepeating("ChangePosition", 0, 1f/speed);
And this speed is also used as multiplier for animation speed.
To give the impression that the snake moves smoothly, the first two parts have animations like the one below ( Don't pay attention to the quality :D ):
And animation works pretty good when i run game first time. But when the snake dies i run:
Invoke("Restart", 0f);
And in next games animation is kind of unsynchronized, on first game when snake moves on new grid then it looks like on screen down below. This are two screens from first step (you have to trust me it is cause you can't see that from screen) on new field but from frist and next game. We can see (I hope) that on bottom picture the snake is moved top a little (its next animation sample).
Cause of that in next games I can see that snake 'flashes' cause animation is shifted forward or backward.
I think i made it work properly by unable loop in animations and play animations from script every time when snake move on next field. But I have no idea why it didn't work properly (I thought every game after restart is like 'clone game', should be no difference) and I don't think my solution of this problem is best solution of this.
Can anybody explain me that?