Jump to content
  • entries
    44
  • comments
    19
  • views
    2315

Day 28 of 100 Days of VR: Adding A New Tank Enemy

Josh Chang

635 views

Welcome back to day 28!

Yesterday, we started our next task on creating multiple new types of enemies and made a new bandit enemy.

Today, we’re going to create our last enemy, a slower enemy with more health that won’t get pushed back as far.

Today is going to be very similar to yesterday, however we’re going to try and create a new animator controller for our enemy. We’ve seen this before in the Survival Shooter, which I once again blissfully ignored, however we’re re-visiting this topic today.

Let’s get started!

Step 1: Acquire new asset

Let’s return to our favorite place in the world! The candy store Unity Asset Store!

Just like yesterday, we’re going to look for an asset that’s mecanim ready.

If you’re not aware of the glory that is the mecanim system, you can visit Day 11 where we first used it.

Step 1.1: Get Zombie Asset

Browsing around the asset store for another enemy to use and I found a nice barbarian mage to use for our tank enemy!

It’s called Zombie01:

 
0*GVOFtCDSArTsc00y.png

Download and import the barbarian into our game. It’ll be in Assets > Zombie_0_1.

Step 2: Setup the Zombie

Yesterday, we created our Bandit enemy that we re-use our existing Knight Animator Controller, however for our Zombie I want him (it?) to have different move set and animations.

Today, we’re going to do things differently!

Step 2.0: Set Wave 1 SpawnManager to Spawn -1 Enemies

If you have set our Wave 1 to spawn -1 enemies already then you don’t have to do anything.

However, if not, go to our SpawnManager and make this change:

 
0*WsvXq3Rzdrk_z4gg.png

Step 2.1: Creating an Animator Override Controller

To achieve the goal of creating an enemy with new animations (but the same states), we’re going to use the Animator Override Controller.

An Animator Override Controller allows us to give it an Animator Controller for us to override and put our own animation clips in. This is very handy for us if we want to create an enemy that has the same states from another Animator Controller, but you want to use different animations for each state.

Let’s first create the animator.

  1. Go to Assets > Animator and right click and create a new Animator Override Controller. Let’s call it Zombie Animator Controller.
  2. Set Knight Animator Controller to be our Controller in our Zombie Animator Controller

Now you’ll see something like this:

 
0*m8C85RWGmxmopYKW.png

See how we have the same 4 states from our Knight Animator Controller?

With this we can add our clips in, but which clips?

For this, let’s just re-use the existing ones that came along with the Knight Barbarian.

In Assets > Zombie_0_1 > Animations, we’ll find Zombie_0_1, if we expand the model, we’ll see these animation clips!

 
0*VbuNrY9DFXHv3Gaj.png

As you can see we have 8 animation clips attached:

  • attack0
  • attack1
  • death
  • idle0
  • idle1
  • run
  • skill0
  • wound

If you want to see what each of the animation does, click on the model and you’ll see the clips that are attached and what they each look like:

 
0*7td9kxoCmtIVv_Z6.png

Unfortunately, because these animations share very similar names, I’m going to have to rename them.

The 4 we’ll need are attack01, death, idle0, and run. Click on each of them and hit Ctrl + D to duplicate them.

Rename each of them to be ZombieAttack, ZombieDeath, ZombieIdle, and ZombieRun.

Move these into our Animation folder.

Here’s what we have:

 
0*PKjICLoqTViGeQuZ.png

Back to our Zombie Animator Controller, let’s add our clips in and we should have this:

 
0*nNuVk1gczhuXroq-.png

Step 2.2: Attaching the Animator Controller

Now that we have created our Animator controller, let’s create our zombie to use it!

  1. In Assets > Zombie_0_1 > Animations drag the Zombie_0_1 model into our game’s hierarchy.
  2. Add a new Animator component and inside for the Animator Controlleradd our Zombie Animator Controller.

Here’s what we should have now:

Note: The Transform position could be anything. I moved it closer to the player, but in the end, it’s not going to matter, because we’re going to spawn it in our present locations.

Step 2.3: Attaching the Nav Mesh Agent and the 3 scripts: EnemyHealth, EnemyAttack, and EnemyMovement

At this point, everything that we’re going to do is going to be the exact same as the day before.

Select the Barbarian game object and add a Nav Mesh Agent Component, Enemy Health, EnemyAttack, and EnemyMovement script to it.

Step 2.4: Setting up the Scripts and Nav Mesh Agent

Now that we have attached our script, we need to set them up.

Nav Mesh Agent

For our Nav Mesh Agent component, we want to adjust the speed of how fast it moves.

Let’s set the Speed to be 2. Our Knight’s speed is 3 and our Bandit’s speed is 3.25

EnemyHealth

For our Enemy Health we want to set:

  • Health: 15
  • Hit Sfx Clips > Size: 4
  • Set the 4 new Audio Clips to be Male_Hurt_01 — Male_Hurt_04
  • Hit Sound Delta: 5

EnemyMovement

For the EnemyMovement scripts, we want to set:

  • Walking Clips > Size: 4
  • Set the 4 new Audio Clips to be Footstep01 — Footstep04
  • Walking Delay:7
  • Knock Back Force: 9

EnemyAttack

We’re going to do some re-work with our EnemyAttack script, technically speaking, we should use sound effects that are not punching sounds, however, because we’re only practicing, let’s just use the same sound effects we have been using.

  • Attack Sfx Clips > Size: 3
  • Set the 3 new Audio Clips to be Punch_01 — Punch_03
  • Leave the Fist Colliders alone for now

Now if we were to play the game, our Zombie will start chasing after us, but he won’t attack us yet, we haven’t set up our triggers and colliders yet!

Step 2.5: Adding 3 Colliders: Trigger Collider, Mesh Collider, and Fist Colliders

At this point, we’ll be doing nearly the exact same thing as we done yesterday.

We’re going to add:

  • A Capsule Collider to be used as a trigger to tell our zombie to enter attack mode if he’s near the player.
  • 2 Box Collider that will be attached to the zombie’s weapon to tell when we damage the player.
  • A Mesh Collider to be used for detecting when the player shoots the zombie.

Adding the Capsule Collider

Select Zombie in the hierarchy and then add the Capsule Collider component.

We’ll make it a trigger, set the Y to be 1, and then expand Radius to be 1.5.

When you’re done, we should have something like this:

 
0*o3Ehaq3_Hu-GbP_X.png

Note: the radius is the outer sphere that you see.

To do a re-cap, whenever our player enters the circle, in our EnemyAttack script, we’ll hit OnTriggerEnter() which is used to tell the bandit that it’s in range to be able to hit the player.

Adding the 2 Box Colliders

Next up, we need to attach colliders to our weapon.

The process won’t be too different compared to working with fists.

In Zombie > Bip001 > Bip001 Pelvis > Bip001 Spine > Bip001 Spine1 > Bip001 Neck Bip001 L Clavicle > Bip001 L UpperArm > Bip001 L Forearm > Bip001 L Hand > Zombie_0_1_002

We want to attach a box collider. We’re just going to make it as big as our weapon.

We need to make some changes with the collider. Specifically, the Z value for Center and Size.

  1. Set the Z value for Center to be 0.6
  2. Set the Z value for Size to be 0.2

The reason why we’re doing this is because we don’t want our weapon to block our gun raycasting when we try to shoot the enemy.

Next, we’ll attach our FistCollider script to our game object.

At this point, we really should call it a weapon collider, but we’ll keep it the same for simplicity.

When we’re done, we should have something like this:

 
0*WXRbEqWzJ0ytm2sG.png

We’ll do the exact same thing for the right weapon as well.

Adding the Mesh Collider

Next up is our Mesh Collider component.

The same as yesterday, the purpose of the Mesh Collider is for 2 reasons, it allows us to:

  1. shoot the enemy
  2. get pushed by the enemy

For the zombie, this is easy.

All we need to do is add a Mesh Collider component to Zombie > Zombie_0_1.

And for the Mesh, attach Zombie_0_1

When you’re done, you’ll have something like this:

 
0*wpfT_zPk4rZquy3z.png

Note: it has come to my attention, that using Mesh Colliders wouldn't be the best approach. Instead a better approach that was brought to light to me by Scouting Ninja is to use individual Colliders that covers our enemies.

However, seeing how we already have this, I'll leave that as a future optimization we can do.

We’re almost there, we still need to make our game object shootable so we can hit him.

Step 2.6: Set Zombie Layer to be Shootable

Straightforward, just like our Bandit, we did the day before, we want to go to our Zombie and change his layer to be Shootable.

 
0*eBxDbHWMra8bRfLO.png

Step 2.7: Attach the Fist Colliders to EnemyAttack

We attached our First Collider script to the Zombie’s weapons. It’s time to attach both of them to our EnemyAttack Script so we can detect when the weapon makes contact with the player in Attack().

In EnemyAttack set:

  • Left Fist: Zombie_0_1_002
  • Right Fist: Zombie_0_1_1

With this, we can take damage now.

Except for two problems:

  1. If we don’t move and let the enemy attack us, he just stops attacking us at one point!
  2. We don’t take damage when our enemy attacks!

Step 2.7: Allowing Enemies to Continuously Attack Us

Fixing the enemy not attacking problem turned out to be straightforward.

If we were to look at the Animator of our zombie when he attacks us, you’ll notice something interesting.

The zombie is in the right state attack state, but he only attacks us once.

One possible area to look at next is the animation clip: ZombieAttack.

Looking at it, the problem becomes apparent. Our Loop Time is not checked, which means that our animation won’t loop!

Check it and we’ll solve our first problem.

 
0*WpK_vKzsvdIK7EHx.png

Step 2.8: Creating an Event in our Animation to Call Attack()

The next problem is that our player character doesn’t seem to notice when they get attacked.

If we were to do some print debugging, if we were to add a print statement inside our EnemyAttack script at Attack(), we’ll notice that we never call Attack()!

As you might recall, we call Attack() by setting an event in our animation! Our Bandit was using the same knight attack animation so we never had to run into the problem, however, our Zombie uses a new animation!

Let’s fix this:

  1. Select our Zombie game object
  2. In the Animation Tab (Window > Animation), select our ZombieAttack clip.
  3. Experiment around with what’s a good frame to add our event, but I chose frame 21
  4. After creating our event, set the function to run to be Attack()

When we’re done, this is what we’ll have:

 
0*9PObtAn8i4tNsesM.png

With this added in, the Zombie can now damage us!

Step 3: Create a prefab

Now that we finished our Zombie enemy, the last thing we need to do is to add it to our Prefabs folder for our SpawnManager in the future!

We can just call our new prefab Zombie.

Conclusion

There we go! Now we have 2 more enemies that we can spawn in the game!

Here’s what we have now:

 
0*KadA_1xnUn4f4x0k.png

With all our new enemies, the next thing to work on is setting our SpawnManager to create new waves our enemy.

We’ll set that up next time! Until then!

Source: Day 28

Visit the 100 Days of Unity VR Development main page.

Visit our Homepage



0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Advertisement
  • Blog Entries

  • Similar Content

    • By GameTop
      Dirt Bike Extreme - another game made with Unity. Took about 2 months to complete.
      Take part in extreme motorcycle races across the dangerous and challenging tracks. Dirt Bike Extreme is easy to pick up but hard to master. Race, jump and crash your way and other mad rivals through the amazing tracks as you master the skills and physics of motocross in this high-speed racing adventure. Conquer challenging routes on 23 different runs, discover new bikes and become the best of the best! Over 257K downloads already!
      Windows Version:
      https://www.gametop.com/download-free-games/dirt-bike-extreme/

      Mac Version:
      https://www.macstop.com/games/dirt-bike-extreme/
       

       


    • By Sergio Ronchetti
      Continuing to work on “Eldest Souls” (first article here!), I’ve begun familiarising myself with the workflow between Fmod and Unity, and the integration system. I know much of this will be pretty obvious to most, but I thought I’d share my thoughts as a complete beginner learning the ropes of sound designing. 
      The library of sounds that Fmod provides has been very useful, at least as reference points. I’ve still kept to my ethos of producing the sounds myself as much as possible. Having said that, Fmod gives you 50 free sounds with your download, and I’ve used a wooden crate smash, a drawbridge and electricity sound you can hear in the foley video below.
       
       
      The thing i found most useful was witnessing changes i made in Fmod being realised instantly in Unity. If a volume needed changing, or the timing of one of my effects was off, i can literally switch to Fmod and then back to Unity and immediately see the result of my alterations. It also seems apparent that using middleware such as this (or i've heard Wwise is also equally intuitive) grants the developer, and myself included, a great deal more flexibility and opportunity to edit sounds without going all the way back to a DAW, and bouncing down again. Needless to say, my workflow is so much faster because of it.
      I've also loved the randomised feature of Fmod, whereby any sound can be made to sound slightly different each time it is heard. Taking a footstep recording i made for example, I was able to add further authenticity of uneven footsteps by randomising the pitch and volume of each playback. 
       

       
      I used this technique when creating footsteps for the first major boss in the game called "The Guardian". A big, over-encumbered husk of a monster. I also had fun rummaging through the garage for old tools and metal components for the “Guardian” (the first boss) footsteps. See below!
       
       
      I also created a sword attack for our player, trying to sound different from the generic “woosh” I see in so many video games. I used a very “sharp” and abrasive sound to differentiate him from any enemies.
       
       
      On another note, I recently upgraded my microphone to a Rode NTG2 shotgun, which has been phenomenal. I haven’t had to worry about noise interfering with the clarity of my objects, whereas before with the sm58 I had to be clever with my EQ and noise reduction plugins.
      Important to note again that this still a “cheap” mic in comparison to most other products on the market, and all in all my entire setup is still very simple and affordable which I’m quite proud of. I’ve seen many musicians spend heaps of money on gear they don’t necessarily need. I much prefer being resourceful with less equipment, than to have more than I can understand or remember how to use.
      It’s forced me to understand every aspect and capability of my tools, which I believe is a principal that can be applied to any discipline.
       
      I have more fun little sound effect videos on my Instagram for those interested, where I post regular updates. Thanks for reading! (if you’ve made it this far)
       
      www.sergioronchetti.com
      INSTAGRAM
      fallenflagstudio.com
    • By Sergio Ronchetti
      BASICS IN SOUND DESIGNING FOR VIDEO GAMES
       
      Recently I joined the talented team at Fallen Flag Studio as the composer for their latest release "Eldest Souls" which consequently lead me into a field I have always dreamt of trying - sound design!
      Having no prior experience, I began watching a few online tutorials (if you want to learn from anyone make it Akash Thakkar from "Hyper Light Drifter"... what a guy!) and basically just testing stuff out i found around the house. Luckily my dad has a garage FULL of random crap to use.
      Before i continue, it's important to note that i DO NOT have fancy equipment, meaning anyone can try this. (my equipment is an sm58, focusrite scarlett interface and Logic Pro X plugins... that's it!)
      I started basic with some footsteps, which weren't all too difficult. Then I moved on to projectiles and a spear attack one of the bosses has. Below are a couple super short videos on my resulting attempts.
       
       
      Amazing how great a banjo sounds for that typical "woosh" sound! And if you're wondering, the paper was added to give some texture to the jab.
      I could be finding a lot of these sounds in libraries online (like the built-in ones that come with Fmod and Unity) but I've chosen not to, in order to produce authenticity and hopefully a more unique gameplay experience for players when the final product is put together.
       
      P.S. if you'd like to try the game and hear my hard work we'll be at EGX and several other conventions later this year, soon to be announced! Thanks for reading!
      www.sergioronchetti.com
      fallenflagstudio.com
       
      To those interested, there's an Alpha trailer of the game in question below.
       
       
    • By OConquestGame
      Hello there!
      I’m the creator and producer of an upcoming visual novel / video game. 
      My team and I are looking for artists (character and background), writers (experienced in writing relatable characters and witty dialogue), and programmers (familiar with unity and creating mini games). 
      Our team is a group of close friends looking to break the mold of the traditional visual novel and create something new and positive. This game will be highly promoted and be a great portfolio piece. Rates are negotiable!
      If you are interested please contact/message us today! OConQuestGame@gmail.com
    • By Kamal Wafi
      Hi there,
      i recently start learning unity and im working in my first game ,
       
      I was wondering if unity had functions to support the motion control effect (tilting screen to move character) you see
      in doodle jump (which is 2d game) ? If it exists, what are they called? and how it works ?

      Thanks
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!