- Home /
Animation Impulse System?
I'm working on an animation system for an RTS game. Each unit has several animation states: Move, Idle, Engaging, etc.. Units also have a variety of "Animation Impulses" which are animations that get played on top of the animation state. They're for things like shooting or casting a spell. When the impulse finishes, the unit returns to its current animation state.
Using Unity Mecanim Animators, how can I make a system like this? Is there a way to PlayOneShot an animation impulse that reverts back to a base animation when the impulse finishes? I.e. a unit is pointing his gun at the target. The unit fires its gun and acts out the recoil. After the recoil animation finishes, the unit returns to pointing its gun at the target.
Answer by cjdev · Aug 23, 2015 at 03:31 AM
You can use animator controller layers to overlay animations on top of your base state machine animations. Essentially it allows you to blend or overwrite your impulses on top of your normal animation states. They can also be controlled by scriptable parameters just like the base layer.
That might be just the thing! Is it possible to "stop" the impulse animation layer to make it not override the base layer?
I.e. if a unit is in the middle of a shooting animation impulse then gets jinxed with a move command. The unit shouldn't be perfor$$anonymous$$g the shoot animation while moving so it needs to stop in the middle of the animation.
The animation layer is blended into the base layer by a percentage deter$$anonymous$$ed by the weight value. You could set the weight to 0 whenever you want the base layer to be sure to take precedence and then the impulse layer wouldn't overwrite your base layer at all.
Your answer
Follow this Question
Related Questions
how i can stop the animator to play trigger animation? 1 Answer
KeyNotFoundException in animator 0 Answers
Mecanim - Transitioning to the same animation in reverse 0 Answers
C# Help with setting up jump animation 0 Answers
how to make an animation run continuously while you press a button on the keyboard 1 Answer