Implementing an animation command in a commands queue system
Hello. I'm working on a RPG game with "commands queue" or "actions queue" system, however you'd like to call it. I am trying to create a discrete "command" for every possible single action of a character and then combine them into more complex actions using "parallel command", "queued command" etc... So for example an "attack" command would be performed in a form of a queue of simpler commands: move to target, face target, inform the target of the attack, play animation, deal damage.
The problem I am facing now is related to the "animation" command, which I can't figure out a simple way to implement so that the command will receive feedback from the animator to decide if the animation is complete. I can either activate a trigger on an animator or crossfade an animation. Both cases have their own downsides. Activating a trigger makes it more complicated to figure out when the animation is complete: you either need to name the trigger the same as animation and check every frame if the animation is complete, or subscribe the command to an animation event some way. Crossfading animation requires additional input, like the transition time and layer, which will make the command less generic. It becomes even more complicated if the animation has different variations depending on some condition and can be stopped in the middle or messed with otherwise.
Thus I am starting to think that using a command for playing animation is a totally dumb idea. Am I wrong? Maybe there's way simpler way to do this? If not through the command, than how would I implement it so that it works with my commands system? Even if it's just a little advice, I would be grateful.
Answer by KevRev · Apr 30, 2019 at 06:02 PM
I've not played with animation yet, so apologies if this doesn't work, but I would approach this with an object reference check.
Firstly, in your script that's checking commands and animations, define a holder for the animation:.
public Animation currentAnimation;
Then when you set an animation to play if do something like the following:
currentAnimation=selected Animation component;
currentAnimation.Play();
if (! currentAnimation.isPlaying())
{
Do something
Maybe set currentAnimation=next animation
}
else
{
Still waiting for animation to finish
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612200501im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can i stop my shooting animation after playing? 0 Answers
HELP,Watched tutorial https://www.youtube.com/watch?v=Xnyb2f6Qqzg 1 Answer
Animating Sprites Through Separate Script? 0 Answers
How to modify animator transition conditions via script 0 Answers
Animator is not firing transitions. 0 Answers