Skip to content

Commit

Permalink
为所有页面增加官方英文原版链接及内容
Browse files Browse the repository at this point in the history
  • Loading branch information
Caizc committed Aug 5, 2017
1 parent fe9d5ef commit 893cc7c
Show file tree
Hide file tree
Showing 13 changed files with 827 additions and 25 deletions.
96 changes: 96 additions & 0 deletions 2.Agents/2-4.动画.md
Expand Up @@ -96,5 +96,101 @@ MMAnimator.UpdateAnimatorBool(_animator,"Jetpacking",(_movement.CurrentState ==

[本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/animations.html)

# Animations

> **Summary:** 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](https://unity3d.com/cn/learn/tutorials/topics/animation). It will however cover the specifics of the Corgi Engine and how it’ll help you create nice animated characters.

## Animation Controllers

![The Rectangle character animator](media/15009134926090.jpg)

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.

![An example of transition](media/15010347513179.jpg)

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](https://docs.unity3d.com/Manual/AnimationParameters.html) 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.

```csharp
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.

```csharp
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 |
| --- | --- | --- | --- |
| Grounded | Character | Boolean | True if the character is touching the ground |
| 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 |
| Idle | Character | Boolean | n True if the character is currently idle |
| Activating | CharacterButtonActivation | Boolean | True if the character is currently activating something |
| Crouching | CharacterCrouch | Boolean | True if the character is currently crouching |
| Crawling | CharacterCrouch | Boolean | True if the character is currently crawling |
| Dangling | CharacterDangling | Boolean | True if the character is currently dangling |
| Dashing | CharacterDashing | Boolean | True if the character is currently dashing |
| Diving | CharacterDive | Boolean | True if the character is currently diving |
| Gripping | CharacterGrip | Boolean | True if the character is currently gripping to something |
| 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 |
| Walking | CharacterHorizontalMovement | Boolean | True if the character is currently walking |
| 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 |
| LookingUp | Character | Boolean | True if the character is currently looking up |
| Running | CharacterRun | Boolean | True if the character is currently running |
| 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](http://corgi-engine-docs.moremountains.com/how-to-create-character.html)), 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).

-------

27 changes: 25 additions & 2 deletions 2.Agents/2-5.AI.md
@@ -1,7 +1,5 @@
# 人工智能

[Artificial Intelligence](http://corgi-engine-docs.moremountains.com/ai.html)

> 这个页面讲解了 Corgi Engine 的 AI 脚本如何运作。
## 简介
Expand All @@ -24,4 +22,29 @@

-------

[本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/ai.html)

# Artificial Intelligence

> **Summary:** This page describes how the AI scripts of the Corgi Engine work.
## Introduction

![A bunch of AI controlled characters walking around in their natural habitat.](media/15010533399635.jpg)

Right now the engine includes a few **basic AI scripts** for your enemies (or friends). These are components you can add to your characters (simply via the AddComponent button at the bottom of the character’s inspector), and it’ll make them perform actions **without the need for input from the player**. To use them, you need to have a Character setup properly, with (at least) the required components for each AI script. Each AI script may require certain particular Abilities, but all of them require that you have a CorgiController and a Character. You can also try combining them : for example you can add AI ShootOnSight and AI Walk to a Character and it’ll be able to walk around and shoot at your player. **More AI scripts are coming soon** to help you create more diverse enemies, but feel free to create your own AI scripts, it’s really easy and fun to do.

## AI ShootOnSight

This component requires a CharacterHandleWeapon component. What it does is cast raycasts to its left and right, targeting the objects on the layers you’ll have specified in its inspector. If one object hits these raycasts, the AI will **shoot at it** using its current equipped weapon.

## AI Walk

This component requires a CharacterHorizontalMovement component. It’ll allow your AI character to walk. You can specify the desired behaviour in its inspector. From there you can have it patrol (walk randomly and change direction when hitting a wall or optionnally a hole), or walk on sight, which means the AI will “look” (using raycasts) for objects on the layers you’ll have specified in its inspector. If a raycast hits such an object, the character will move towards it.

## AI Follow

This component requires a CharacterHorizontalMovement component. Add this script to a Character to make it follow (or try to follow) the main Player character. If it has a CharacterRun component it’ll try to run when far from target. If it has a CharacterJetpack it’ll try to jetpack over obstacles to reach the target, and if it has a CharacterJump component it’ll try to jump over obstacles.

-------

72 changes: 70 additions & 2 deletions 2.Agents/2-6.武器.md
@@ -1,7 +1,5 @@
# 武器

[Weapons](http://corgi-engine-docs.moremountains.com/weapons.html)

> 这个页面讲解了 Corgi Engine 的武器系统背后的机制,以及如何创建和使用自定义的武器。
## 简介
Expand Down Expand Up @@ -76,4 +74,74 @@ Corgi Engine 中的所有武器都继承自 **Weapon** 类,当然也可以脱

-------

[本页面的 Corgi Engine 官方英文原版链接](http://corgi-engine-docs.moremountains.com/weapons.html)

# Weapons

> **Summary:** This page describes the mechanics behind the Corgi Engine's weapons, and how to create and use your own weapons.
## Introduction

The Corgi Engine includes a **generic weapon system**, allowing your characters to equip a weapon (projectile based, melee, or whatever you can think of), switch to another one, and use it. The engine also includes a few examples of weapons you can have a look at, and that you can use as a basis when creating your own.

## The CharacterHandleWeapon Ability

To be able to equip and use a weapon, a Character must have a **CharacterHandleWeapon** component. From its inspector you’ll be able to optionally select a weapon for your character to start with, define if it can pickup new ones, and specify a **Weapon Attachment**. This is a transform on your character (or nested inside its prefab) for the weapon to attach to. If you don’t specify one, the weapon will attach to the root level of your prefab.

What the **CharacterHandleWeapon** component will then do is check for changes on the weapon use button, and if it gets pressed/released, transfer that information to the weapon currently equipped.

## The Weapon classes

All weapons in the Corgi Engine derive from the **Weapon** class. You can of course divert from that, but that’s how all the examples work. The Weapon class is meant to be extended and will define a lot of things common to all or most weapons. Using it as a basis you’ll be able to create everything, from a shotgun to a rocket launcher, but also a katana or a grappling gun. In addition to providing a solid basis for animations, sounds, state management, it allows you to define in your child class what happens when the weapon is used, and build from there. You can look at the **ProjectileWeapon** and **MeleeWeapon** classes for examples of how you can create very different weapons from this very same script.

## Creating a weapon

To create your own weapon, you can either reuse the ProjectileWeapon or MeleeWeapon scripts as they are, extend them, or create your own Weapon child class. In any case, you’ll then need to **create a weapon prefab**. To do so, you’ll need a gameobject. Basically you’ll have the choice to have a visible weapon or an invisible one. For example if you look at the BlueRobot enemies, they do have a weapon, but you don’t see it, it’s just an empty gameobject spawning effects and projectiles. The MinimalRocketLauncher on the other hand is visible, and even includes tiny (very minimal) hands. That way when it rotates as the player aims, the weapon is always facing the right direction. So decide on that depending on the kind of visual result you’re looking for.

Once you have your sprite, or model, or empty game object, just add your weapon (ProjectileWeapon, MeleeWeapon, or your own) script to it. From its inspector you’ll be able to setup animations, sounds, effects to trigger when firing, and specify how the weapon should flip when the character flips.

Here’s a step by step creation of a Melee Weapon for reference :

* create an empty gameobject
* add a MeleeWeapon component to it

![Our empty game object with the MeleeWeapon component](media/15010648215013.jpg)

* in the MeleeWeapon inspector, set the following parameters : Trigger Mode to Semi auto, Damage Area Shape to Rectangle, Area Size to {1,1}, Area Offset to {2,0} (so that the damage area will activate in front of our character), Active Duration to 0.2 (it’s a short attack, a punch basically). Then set the Damage Caused Target Layer mask to Platforms and Enemies, and 10 damage.
* rename this gameobject to MeleeAttackWeapon (or whatever you prefer)
* drag this gameobject into your hierarchy to make a prefab out of it
* select your character, and drag that newly created prefab into its InitialWeapon slot (or you can use the ChangeWeapon method via script to equip it)

![Binding the weapon to our character](media/15010663739266.jpg)

* that’s it, you now have a working weapon. Press play, then E (by default), and you’ll be throwing punches around and damaging enemies/objects. But so far you’re probably not seeing anything when attacking. Let’s bind an animation to that attack.
* select your character’s animator, drag your attack animation into it if it’s not already the case.
* create a new animation parameter (the little + button at the top right corner of the Parameters panel), in our example we’ll call it “RectangleMeleeAttackStart”

![Adding a new animation parameter](media/15011218647959.jpg)

* create a transition to that animation. You’ll probably want it to have the following settings (at least the fixed duration), but feel free to adjust to fit your particular animation.

![Adding a new transition to our attack animation](media/15011223989829.jpg)

* go back to your weapon’s inspector, and fill the StartAnimation field with the name of your animation parameter. In our example “RectangleMeleeAttackStart”.

![Binding our new animation parameter to our weapon](media/15011225662440.jpg)

* press play again, attack with your weapon, you now see your character attacking. You can add other animations, for when the attack is in progress, ending, etc.

## Timing

Timing is essential when creating weapons, as you’ll want to sync your weapon’s component to its animation perfectly. All weapons come with two variables you can tweak directly from the inspector : **DelayBeforeUse** (the time between the input registration and the actual WeaponUse - the shot, axe sling, etc), and **TimeBetweenUses** (the time that needs to pass before you can have another WeaponUse (whether it’s in auto, or via repeated presses, etc). The weapon just won’t “shoot” during that time).

Additionally, the melee weapons have two more variables you can play with : **InitialDelay** (the delay between the WeaponUse and the activation of the damage area) and **ActiveDuration** (the time during which the damage area will stay active). These 2 last parameters are very specific to damage areas, and of course you’ll want to sync these values with your DelayBeforeUse / TimeBetweenUses to prevent conflicts.

## Weapon Laser Sight

![The lasersight component in action](media/15011248436120.jpg)

You can add a **WeaponLaserSight** to your weapon. It’s of course more suited for a projectile weapon but there are **no restrictions**. What it’ll do is that it’ll cast a laser in front of the weapon, like a laser sight would. You can set a collision mask so that the laser stops when meeting a wall or platform. From the inspector you can also customize the appearance of the laser.

-------


0 comments on commit 893cc7c

Please sign in to comment.