This page describes how animations are used in the Corgi Engine.

Introduction

The Corgi Engine includes a lot of demo characters, and they all come with a number of animations. In the various demos, you’ll find some characters animated using spritesheets, some using Mecanim, Spine, or 3D fbx animated models. It’s really up to you to choose the animation method that fits your skills and needs. But the Engine should have you covered whatever method you decide on.

This page won’t cover how to create your animations. Unity has a lot of documentation on that, go check it out. It will however cover the specifics of the Corgi Engine and how it’ll help you create nice animated characters.

Animation Controllers

Jekyll
The Rectangle character animator

In most cases you’ll need an Animation Controller to setup your animations. The asset includes a bunch of these, I’d recommend using the RectangleAnimator one as a starting point for yours as it includes all animation parameters, so you won’t have to enter them all again. You can simply duplicate it, and then drag your animations into it, replacing the Rectangle ones as you go.

The Animation Controller is made of two big parts : on one side Animation Parameters that will get updated every frame by the Character and Character Abilities scripts to reflect the current state of the character, and on the other a state machine that will allow you to determine in which conditions each animation should be played and how to transition from one to the other.

Jekyll
An example of transition

You’ll notice it’s very simple in terms of workflow, as most transitions are simply based on the current character’s state, so the hard work of checking the many possible conditions is already done by the engine. Of course you can divert from that and have more complex transitions if that works better for you.

Animation and scripts

The Corgi Engine’s character system has animation interfaces built-in so you don’t lose time on that. Every ability comes already loaded with corresponding animation parameters. To update animation parameters, you can either use Unity’s built-in methods or the ones provided with the Corgi Engine. It’s really quite simple, as from any ability you only need to override two methods. Let’s have a look at how it’s used in the Jetpack ability :

InitializeAnimatorParameters : This method “registers” parameters, for later use. Basically it just adds that parameter to a list, after having checked its existence in the Animation Controller, to avoid potential errors at runtime. If that parameter doesn’t exist, update requests will simply do nothing, without triggering errors. This allows you to share a single animator amongst many characters, without having to copy all parameters into all the controllers. This method is only called at Initialization.

protected override void InitializeAnimatorParameters()
{
	RegisterAnimatorParameter ("Jetpacking", AnimatorControllerParameterType.Bool);
}

UpdateAnimator : This method, called every frame, will update the animator parameters with their current value. In it you should only have calls to MMAnimator.UpdateAnimatorBool/Int/Trigger.

public override void UpdateAnimator()
{
	MMAnimator.UpdateAnimatorBool(_animator,"Jetpacking",(_movement.CurrentState == CharacterStates.MovementStates.Jetpacking),_character._animatorParameters);
}

Adding new animations

To add a new animation, all you have to do is create it, drag it into your character’s animation controller, and create a transition to it. If it requires new animation parameters, make sure you add them both to your animation controller’s parameters list and register/update them in your script(s) using the above methods.

Animation Parameters

Here’s a full list of all the animation parameters already in the engine:

Parameter Name Ability Type Role
Activating CharacterButtonActivation Boolean True if the character is currently activating something
Alive Character Boolean True if the character is currently alive
CollidingAbove Character Boolean True if the character is colliding with a wall above
CollidingBelow Character Boolean True if the character is colliding with a wall below
CollidingLeft Character Boolean True if the character is colliding with a wall on its left
CollidingRight Character Boolean True if the character is colliding with a wall on its right
Crawling CharacterCrouch Boolean True if the character is currently crawling
Crouching CharacterCrouch Boolean True if the character is currently crouching
Damage Health Trigger Triggered when the character takes damage
Dangling CharacterDangling Boolean True if the character is currently dangling
Dashing CharacterDashing Boolean True if the character is currently dashing
Death Health Trigger Triggered when the character dies
Diving CharacterDiveDive Boolean True if the character is currently diving
FacingRight Character Boolean True if the character is currently facing right
Flying CharacterFly Boolean True if the character is using its Flight ability
FlySpeed CharacterFly Float The speed at which the character is flying
Gliding CharacterGlide Boolean True if the character is gliding
Grounded Character Boolean True if the character is touching the ground
Gripping CharacterGrip Boolean True if the character is currently gripping to something
Idle Character Boolean True if the character is currently idle
Jetpacking CharacterJetpack Boolean True if the character is currently jetpacking
Jumping CharacterJump Boolean True if the character is currently jumping
DoubleJumping CharacterJump Boolean True if the character is currently double jumping
HitTheGround CharacterJump Boolean True if the character just hit the ground this frame
LadderClimbing CharacterLadder Boolean True if the character is currently climbing a ladder
LadderClimbingSpeedX CharacterLadder Float The horizontal speed of the character if he’s on a ladder
LadderClimbingSpeedY CharacterLadder Float The vertical speed of the character if he’s on a ladder
LedgeHanging CharacterLedgeHang Boolean True if the character is currently hanging from a ledge
LedgeClimbing CharacterLedgeHang Boolean True if the character is currently climbing up a ledge
LookingUp Character Boolean True if the character is currently looking up
Running CharacterRun Boolean True if the character is currently running
Speed CharacterHorizontalMovement Float The current horizontal speed of the character
xSpeed Character Float The current horizontal speed of the character
ySpeed Character Float The current vertical speed of the character
Swimming CharacterSwim Boolean True if the character is swimming and moving
SwimmingIdle CharacterSwim Boolean True if the character is swimming and not moving
Walking CharacterHorizontalMovement Boolean True if the character is currently walking
WallClinging CharacterWallClinging Boolean True if the character is currently clinging to a wall
WallJumping CharacterWallJump Boolean True if the character is currently jumping from a wall

In addition to that, you’ll find a number of animation parameters in CharacterHandleWeapon whose name you can set from the inspector of each weapon directly.

Spine

If you want to use Spine, there are two ways you can go :

You can “bake” your character via the Spine Unity runtime. All the demo playable characters included in the asset use this method, but I wouldn’t recommend it for your game. The demo characters are baked because that was the only way to include them without having to add the Spine runtimes. These can’t be distributed by anyone else but Spine, so that was not possible. But baking Spine characters prevents you from using all the cool Spine features.

The “best” way to do is to create/animate your character in Spine, then do File > Export, select .json extension and format, check “create atlas”, go to parameters, set the atlas extension to .atlas.txt, tweak the other settings according to your character, and then export to a folder inside your project. This will create a bunch of Spine related files. You’ll then want to select the SkeletonData file, and drag it into a scene. Select the SkeletonAnimator option, and you should see your character on the scene. If that’s not the case, you probably need to select a skin from that new object’s inspector. While you’re at it, select the sorting layer of your choice (Player is the recommended one). You can now drag that object into your hierarchy to create a prefab.

Now there are two things left to do : add your Character’s components (see this page for more), and take care of the animator. Spine animators work exactly like regular ones. Select your Character, and go to Window > Animator. There you should see an empty state machine. Start by adding the animation parameters you’ll need from the list above (Idle, Crawling, Crouching, etc…). Then, from the folder with all the exported Spine files, unfold the Controller animator, and drag and drop the required animations into your Animator. The only thing left to do is to create transitions to all these states, and that’s done exactly like for regular animation controllers (see higher in this page).

Two more things : you should nest your Spine object under the top level of your character (which should be an empty gameobject with just the colliders, CorgiController, Character and CharacterAbilities…). You can look at the NativeSpineCorgi example character for reference, located in Demos/Corgi2D/Spine/NativeSpineCorgi.