Journal 103 — Unity 2D Mobile, Dungeon Escape Moss Giant and Spider Attack

Chris Nielsen
5 min readOct 6, 2021

--

Objective: Build out the Moss Giant and Spider attack animation and behavior

In this article, I will go over the setup for the moss giant and spider attack, which is similar to the steps used for the skeleton attack.

Moss Giant Animation

We can start with adding the moss giant attack animation.

Then we can update the animator blend tree with the transition from idle to attack. This should be the same as the skeleton, with an “InCombat” bool set to true when transitioning to attack, and false when transitioning to idle.

Now we need to add a collider to the moss giant so it can be attacked by the player and then it will react and attack the player.

Moss Giant IDamageable interface

Next we can update the moss giant script to add the IDamageable interface.

After this, we need to update the moss giant animations to add a hit animation, where eventually it will then counterattack the player.

Moss Giant Hit Box

The moss giant needs a hit box added to its attack. We need to add a 2D sprite with a Box Collider 2D and Rigidbody 2D, and record each frame of the attack animation with a changed collider position and rotation.

The last updates are to add the attack script to the hit box, and to also add the moss giant layer and attack layer and make sure the attack ignores the enemy like we set up for the skeleton and player.

Here are the results.

Spider setup

The spider setup will not have as many of the behaviors as the skeleton and moss giant. Essentially it will sit idle and spit an acid projectile that the player needs to dodge and get close to the spider to attack and kill it.

First we need to set up the attack animation. We can add a simple transition between idle and attack with 0 transition duration.

Then we can create the acid animation from a new game object. Finally we can turn the acid game object into a prefab.

Spider Animation Event

During the spider animation, when it rears up and the green light shows from its body, we can instantiate an acid projectile. We can start with a new script that will tell the spider to fire a projectile. We can attach this script to the spider sprite.

In the spider Animation window, we can add an “Event” to call the Fire() function.

Acid Effect Behavior

Now we need to update the C# scripts to instantiate an acid effect at the spider, move the acid effect and destroy it after a few seconds, and cause damage to the player if hit.

Now let’s see the results.

Thank you for your time!

--

--

Chris Nielsen
Chris Nielsen

Written by Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.

No responses yet