Making an Enemy in Corgi

Enemies put you to the test in games, so since they help you improve, are they really Enemies?

Philosophies aside, here’s how we can make a basic Enemy in Corgi for Unity.

Make your entity:

Create a new Game Object. Give it a nice name.
Position it at a desired location. Unity may shift it in the Z-axis which may be undesirable so be aware of this.
Set its Layer to Enemies to ensure they are evaluated as such.

Depicting Layers in Inspector

Define its visual and shape:

At the least, add a Sprite Renderer and set a desired image.
Add a Box Collider 2D for collision detection purposes. Turn its `Is Trigger` on.
Corgi will handle reaction to collisions.

Depicting Unity Inspector and Sprite

Make it a Corgi character:

Add a Corgi Controller and set its collision masks.
Masks in Corgi Controller

Add a Character component. The default type is AI, so we’re good to go.
At this point, we have a Corgi enemy that can stand still but not much else.

Make it move:

By adding AI components, we can give it varied behavior.
Add an AI Walk component and turn on Avoid Falling. 

AI Walk Script

Make it dangerous:

Add a Damage on Touch component and set the Target Layer Mask to Player to let it damage the protagonist.

Player now gets Damaged

Now it is a foe to avoid. By adding more behavior, we can further define our Enemy AI.

Experiment and have fun.

 Date: October 20, 2018
 Tags:  gamedev guides unity

Previous
⏪ Money at Work

Next
Tom Clancy's The Division 2 ⏩