Animation events let you link timing in your animations to other stuff! When an event is hit, it will call a function on a script on the animating game object.
To add events, open the animation in the PowerSprite Animator window, double click the 'timeline' to create the event, then type the name. You can pass a variable in, select the type with the dropdown (bool,int,float,string or object). See the PowerSprite Animator documentation for more info- PowerSpriteAnimator-Manual.pdf
Note: For built in events, you'll need the "Add 'Anim' prefix" tickbox to be ticked.
Built in Animation Event functions:
Character Animations
- Footstep - Plays the character's current footstep sound. Change the current footstep sound cue like this:
C.Dave.Footstep = "FootstepMud";
- Mouth (string new - Change the 'Mouth' animation
- LoopStart / LoopEnd - For looping anims with in/out transitions. (eg: Crouching to pick something up). When the LoopEnd event is hit, the anim will jump back to the LoopStart event, until the anim is stopped/changed, when it will play the rest of the anim. Example Gif: https://i.imgur.com/BWJFGac.gif
- Offset - For use in character animations that moves character from Node1 to Node2. Useful for anims that have character movement built into them.
- Sound (string cueName) - Plays the sound cue with the name set in the 'string' field.
- Sound (object cue) - Plays the sound cue you've dragged into the 'object' field.
- Spawn (object gameObject) - Creates the game object you've
- WalkSpeed (float speed) - Temporarily override character walk speeds. Useful for walk anims like "limping" etc. Example Gif: https://i.imgur.com/Y9W0pgF.gif
- WalkSpeedX (float speedX) - Same as WalkSpeed, but only changes horizontal walk speed.
- WalkSpeedY (float speedY) - Same as WalkSpeed, but only changes vertical walk speed.
- WalkSpeedReset - Resets the walk speed to what it was before other WalkSpeed tags were hit. If ommitted, the speed will be reset at the end of the animation.
Prop Animations
- Sound (string cueName) - Plays the sound cue with the name set in the 'string' field.
- Sound (object cue) - Plays the sound cue you've dragged into the 'object' field.
Custom Events
If you have a function in your Global or Room script, it will be called when an Animation Event with the same name is hit.
For example, if you have an event called "Gunshot" in your anim, it'll call a function called Gunshot()
if you add it to your room script.
Event Triggers
Props and Characters have some useful functions for using Events to trigger things. The simplest and most useful is the Prop or Character function:
WaitForAnimTrigger(string eventName). The causes the script to wait on this line until the anim event is hit.
C.Barney.PlayAnimationBG("Shoot");
C.Barney.WaitForAnimTrigger("Bang"); // Wait for the 'bang' animation event.
Audio.Play("Gunshot");
Camera.Shake(4);
Dave: Ouch!!
E.WaitWhile(()=>C.Barney.Animating)); // Wait until the animation finishes
This would start the animation in the background, then wait for the 'Bang' animation event. Once that is hit, it will continue the script.
AddAnimationTrigger(string eventName, bool removeAfterTriggering, Action action) is a more advanced and complicated function to use, but lets you set up some code to run on the event before the animation is played. Useful for short events, or if you don't want to use a background animation. eg:
C.Barney.AddAnimationTrigger("Bang",true,()=> Camera.Shake(4) );
Barney: I'm going to shoot you now
C.Barney.PlayAnimation("Shoot");