We need to retrieve a reference to the velocity component in the keyboards Awake function (more information on how the Awake function operates can be found here). I have also changed the default move speed to 300.
Right now we have to perform a check at the beginning of the function to see whether we are currently playing the projectile attack animation. Without this check, the function would override the projectile animation state and it wouldn’t play the animation at all (a problem we had last week. This solves our problem for now but what happens when we add a melee attack animation? We’ll need to add another check here. And then we’ll need further animations: death, hurt, picking up items etc. When the games finished we may have 100s of checks here and in many other places (because we don’t want the projectile attack overriding the death animation for example). This is not a sustainable way of writing an animation system. But like many of our systems, this is not its final form. We’ll soon be writing a more robust data structure, most likely a finite state machine, to handle the animation states more elegantly. There are also other options we can look at for inter-system communication including a message queue and event system but that’s for another day.
But we’re not out of the woods yet, once the animation starts we are stuck with that animation. There is no way to stop the animation and it will continue to loop until we quit the game. Because the animation is set to loop and our new movement component is instructed to do nothing while the projectile attack is running we can only watch as the player shoots one non-existent projectile after another. Also, we can move while the projectile animation is in progress. These are two things we will fix next week when we start work on creating one-shot animations (animations that only play once and then transition to a different state).