Download

State machine alternating attack trouble

Spent all day today trying to figure this one out on my own.

I’ve created an animation state machine that contains the standard moment and jump states (like the 3rd person example). I’ve added in a combat state, and inside that I’ve created a light attack state. I want to alternate between left and right sword swings, but I can’t seem to get the logic right to make it happen.

Specifics: Alternate between left and right swings. After first attack there should be a short time window that if I hit the attack button again, it will allow me to move into the second attack, and continue on back and forth. And no matter how many times I mash the button, I only want the new animation to play once the old one is finished, but to start playing with the first attack button hit after the animation is finished.

I am using anim notifies for the time window between each swing (placed towards the end of the animation). I’ve created several “creative” ways to make it halfway work (using a bool to check if the attack button is pressed, then delaying a certain amount of time before setting the bool to false), but the delay begins to bog down after a while if I’m button mashing. I know there has to be a better way to do this.

Any help would be appreciated. I’ve attached pics below, if you need anything more specific let me know.

State Machine:
746f792137482221fdafd3b117066c19e424a284.png

Character Blueprint:
2693ade149e07d01d117b95b2c3843460987d01d.png

State Machine Blueprint:
a7527ebf6292c2c950c62d4a152b8db62eb9af4a.png
34f96fca13abfe68961db5833dbb7c1b4f1a77d4.png

Yeah always post screenshots. It helps a lot.

I do a video blog for our community and did an overview as to our current design that might help you out.
https://youtube.com/watch?v=KoCWsVPw8I8
Be warned its wordy.

As an opinion the state machine really should be used only for body movement and attacks done using per bone blends as well to always be casting for new input. As for playing one animation only after anther has been completed that’s what a Montage is for as you can set it up so another action can not occur until the last one has been completed.

The problem I had with using a montage is that I couldn’t control the timing of the second attack. Setting up the timeframe window and continuing it was easy enough, but I wanted the attack to be responsive to the attack button, not just continue a single animation. Is there a way to to that in a montage? Say I’ve got a 2 second window to continue the next attack. I want to have the option of continuing into the second attack immediately for two quick hits, or to wait until the very end of the window and space the timing of my hits out a little. I couldn’t figure out how to make montage work that way so I switched to a state machine.

I will def check out the video though, thanks man.

Well the montage is designed to give the animator better control over melee attacks and much better conditional branching than you could ever do inside of a state machine. In general delays are nasty as they can effect proper timing and I suspect that your bogging problem is caused by a conflict between the delay and the in and out argument inside of the state machine. (been there done that)

Later in the video I posted you can see that I have all of my attacks set up as montages that fires as an absolute rather than having two arguments arguing with one another inside a state machine.

As to ideas that you can do boy there is a ton that does not effect the animation timing using a montage and an argument (and there are lots) that you can’t do in a state machine and you just have to write the argument out as a logic block (just like you done above)

By the way Zak does a number of montage examples in the learning section that I stole most of my ideas from. :wink: