Welcome back to Day 11 of my 100 days of VR development!
Continuing from where we left off, we have a cube as an enemy, we can do better than that. In fact, today, after playing around with creating my own character animations with rigging and Unity’s Mecanim system and I’ll tell you that I can finally begin to appreciate what Unity provides for amateur developers.
What am I talking about? You’ll see!
Getting the Assets
The first thing I did for the enemies was that I went straight to the Asset store to find a free model that I can use.
As expected, they exist.
Here was a couple that I found:
Don’t ask me why 2 of the 3 models were skeletons. They just were okay!
I imported the first toon skeleton into my game and went to create my Animator Controller for it, but at this point I realized something important.
There aren’t any death animation clips for the model!
Without knowing anything about 3D modeling I’m stuck.
Having no choice I decided to move on and look at the next skeleton. It has 9 animations, including death, which is exactly what I needed.
Feeling happy having one working model, I went to the next one the Strong Knight. Reading the description, it says: “mecanim humanoid rig(no animations!)”.
What does that mean?
I investigated further and here’s what I learned.
What are rigs?
Rigs are basically a skeleton structure for our character models. Unity provides classifications for these, the most common one being humanoid creatures.
From my understanding, we can create animations by capturing the movements of these bone structures to create an animation.
What this means for us is that if we want to animate the Strong Knight, we need to get Blender and Rigify to create the animations…
…yeah, no thanks. I’m a programmer. I want to write code, not mess with 3D modeling software like Blender.
Luckily (for rig models anyways), Unity has a solution. We can use Unity’s Mecanim animation tool to use existing animations!
What is Mecanim
We’ve actually already seen Unity’s Mecanim system before. It’s our animator system. We used it to create our Animator Controller. Remember this?
Remember in the Survival Shooter tutorial series, I skipped the part where we made the Zombear, because I couldn’t find any animation models for it? We’re coming back full circle to it.
In Unity, if you have rigged character models that have similar bone structures to other rigged characters, we can actually share the animations from one character model to the next.
Here’s what I mean by humanoid body structure. As long as our model has these similar points, we can share the animation
For example: our Zombunny had animation clips that we used, but because our Zombear had a similar humanoid structure to our Zombunny, we can re-apply those animation effects on our Zombear without needing to have those same animations!
Ahhhhhh! It makes sense now.
After looking around for animatiosn in the Unity Asset Store, I found a lot of animation that can be used for free!
I chose to use the Mecanim Warrior for their death animation
And I chose to use the Warrior Pack Bundle 1, for the Brutes animation. Downloaded everything? Good!
Next to keep everything organized, I made a new folder called Animation in my project.
In that folder, I created a new Animator Controller which I called, Knight Animator Controller.
Next I dragged in the animation clips from the models we downloaded and add them into the animator. Specifically:
- death from Mecanim Warrior
- Attack1 from Brute Warrior Mecanim
- Idle from Brute Warrior Mecanim
- Run from Brute Warrior Mecanim
Next, create 3 parameters:
- IsNearPlayer – Bool
- Idle – Trigger
- Death – Trigger
Finally we have to connect everything together.
- Run is our default state
- Transition from Run to Attack1 when IsNearPlayer is true
- Transition from Attack1 back to Run when IsNearPlayer is false
- Transition from Any State to death when death is triggered
- Transition from Any State to Idle when idle is triggered.
The goal is that if the enemy is near the player, they’ll start attacking, otherwise, they’ll run after the player.
When you’re done, we should have something like this for our Knight Animator Controller
Next drag the String Knight prefab into the scene and in the Animator component, attach our animator to our knight and he’ll be off running!
Also don’t forget to disable/remove the Rotation script that’s attached to the Strong Knight game object.
Of course, if you want to try and see what happens in the other states, you can set the other states as the default and see what our Knight would do.
And there we go! Now we have the animation for our knight character!
Stepping back and reflecting
Now before we move on. I want to step back a bit and explore what we did.
What we essentially did was that we took multiple random rigged character model from the Unity app store that has their own animations and created an animator controller for our Strong Knight.
The amazing thing is that we only had one animation clip from the creator: idle.
The other animations we’re using are all from other animation packs/characters that we can just take and apply into our animator for a knight. That’s CRAZY!
What this means is that as a developer. I don’t need to know how to do 3D modeling. As long as I have a rig character model, I can apply other people’s animation to my character as long as they share a similar rigged body. That’s a crazy powerful feature right there!
Well, that’s enough excitement for day 11. I spent quite a bit of time looking into rig character models, searching for animations, and then experimenting with how I can use any humanoid animations for the Strong Knight model that we created.
Tomorrow, my goal is to start writing a script for the enemy and creating a navigator agent for our enemy so that they can start chasing after the player.
See you guys tomorrow for Day 12!