-
-
Notifications
You must be signed in to change notification settings - Fork 13
Home
If you press the movement inputs too quickly, frogger can become misaligned with the grid and possibly go out of bounds in unexpected ways. This is caused when a new leap animation is performed while the previous leap animation is still ongoing. One way to fix this is to add a cooldown after frogger leaps so they have to wait before leaping again. The cooldown will last only for the duration of the leap animation to finish.
Let's first add a new variable to our Frogger class:
private bool cooldown;Then, in the Move function we will only proceed with the movement code if not on cooldown:
private void Move(Vector3 direction)
{
if (cooldown) {
return;
}
//...
}Finally, in the Leap coroutine function, we will set the the cooldown to true and false, respectively:
private IEnumerator Leap(Vector3 destination)
{
//...
// Start cooldown at beginning of coroutine
cooldown = true;
while (elapsed < duration)
{
// existing code...
yield return null;
}
//...
// Stop cooldown at end of coroutine
cooldown = false;
}There could be a few different reasons for this, but the main reason is likely that you have not changed the Sorting Layer and/or Order in Layer properties on your SpriteRenderer component. These properties determine the order in which sprites are rendered. Your sprites might just be rendering behind your background elements, causing them not to be seen.
I recommend using the following Order in Layer values for your sprites:
-
1: Frogger -
-1: Road/Water -
0: Everything else