I believe I’ve built a functional Finite State Machine for my game, but I’m running into a persistent issue with animations. Specifically, while all the main animations work fine, adding in an attack when a button is pressed is causing the animation to continue over and over for as long as the attack key is pressed, or to stick with the attack animation (just once) until another button is pressed. The latter of these is what I am seeing right now.
I set up a timer called attackTimer that is meant to give me a variable to work with for this. I meant for it to be a cooldown, but no matter how many times I implemented it with variying delays, I still had issues. The attack animation itself is very quick, 0.05s, and I had things set so when the F key (my attack button for now) is pressed, the animation changes to Attack1. At this point the timer is started, and the attack animation is played. Only when the timer was past 0.05s would the attack button repeat the action, and if it wasn’t pressed, after 0.05s the character would return to idle (or any other state, i.e. falling or jumping).
What would happen though is this: holding down the F key caused the player to attack over and over on a loop until released. Alternatively, by moving the attackTimer requirement around, I was able to get it to play the attack animation only once but if I was to move, jump, fall, or anything else while still holding the F key, the animation would start over again.
My main goal here is this - the player can run, jump, fall, etc. and if the F key is hit, it will animate an attack (and create an object for checks), but when finished, return to the state the player would otherwise be in. I want to be able to attack on the run, or when jumping, without causing the entire animation process to stop or allowing the player to attack endlessly by just holding the key down… like a metroidvania would allow. Hope that makes sense.
I feel like I’ve tried 100 things and it’s not working. Hoping maybe someone here can help? Here are some screenshots of the main “Finite State Machine” that I thought I build right:
As a new user here I can only post one image, but here’s one of the functions I made:
The same thing applies essentially for each movement option - idle, falling, running, and jumping.