Combat Script : Stop Attack script on animation end.

Hi there!

I have a Combat Script with multiple skills.

My issue is knowing which skills animation ended.

Lets say I have 3 skills :

Punch, Kick, and Mega punch.

If I Punch, I will start the punch animation, and at the end of the animation, I want to call a function in the skill itself to stop the skill.

My issue is, my animation doesn’t know which skill called it.

Like If I punch, I use the punch animation, but Megapunch also use the punch animation.

To get over this, I keep the last used skill in a variable. So when the punch animation end, it check the lastSkill variable and knows it was the punch skill that triggered it.

Alas, it doesn’t work when I cancel an attack with another.

Punch can be cancelled by Kicks. When I start Kicks, it transition the animation from punch to kick. The thing is, by the time kick started and is now the lastSkill used, Punch will end it’s animation and call the Stop skill function. Sadly, lastSkill is now Kick, so it stop the kick when it should stop the punch.

I’m a bit stuck, I don’t know if my explanation are clear or not.

Thank you!

Why not use an animation event? Your animations can invoke a “StopSkill” method with a string or int parameter that identifies which skill it is.

1 Like

@JoeStrout

Thanks for the reply!

That’s what I am using. I actually tried both animation Events and State Machine Behaviours with OnStateExit.

The issue is : An animation can be used by multiple skills. When it call the StopSkill method, I can’t send a parameter to identifies the skills, because the animation doesn’t know what skill it is.

send it to a script that already knows what skill it is
ie. when you change animation/skill, change the variable on the script that the animation event is using (and then can stop that skill)

okay, I think you got this down, but you have a problem with the variable.
looks like Kick is not the lastSkill, but the recent one.
so you can have one more variable that registers the skill before the ‘lastSkill’
or in the script the lastSkill should come later

1 Like

OK, let me see if I’ve got this straight.

You have code with a concept of “skills,” which can appear as some combination of animations. And that code needs to know when the animation is done. But trouble is, a skill can be interrupted by another skill, and your animation-done events from the previous one will then fire, prematurely ending the new one.

And since an animation can be used by different skills, it’s not easy to see if the animation ending is really the end of the animation.

Well, if you’re using Animation Manager state machines, I think you might have to move all concept of skills into that. In other words, you have a branch in your state machine for each skill, and it chains the necessary animations, and also has transitions for interrupts (as when one skill cancels another)… and at the very end of the chain, the last state fires an event that notifies your code of the completed skill. The animations can get reused however you want; the skill you’re on is defined entirely by what part of the state machine you’re in.

If you’re not using Animation Manager state machines, but instead playing animations yourself, you can do the same thing with your own state machine. Each animation can send an animation event signalling that it’s done, along with its own name. Your code will have to be clever enough to only pay attention to the expected animation-ends, ignoring all others (that may be leftover from some previously canceled skill).

1 Like

@dibdab

I tried to create variable managing a queue of my skill to handle the before lastskill thing.

I had an issue with it, but I dont remember which. I also had to do with transition, I will have to check it out again tonight.

@JoeStrout

I’m afraid I will have to do this. I didn’t want to create an animation for each skills, as a lot of them could be reused. It might be the easiest way to make it works.

I will prolly use the animation manager, and set event which call function with the skill ID.

Thank you!