How to add an animated creep to TDTK (by Song tan) for #Unity3D #Tutorial

Published in IT Solutions

Adding an animated creep to TDTK in Unity

A guy by the name of Song Tan (Song's blog) has build really nice Tower Defense building starter kit for unity called TDTK. If you've purchased it then you know it makes creating a tower defence game reasonable easy. I didn't have any problems getting creeps into my game, but I did have problems animating them. So here is a guide to adding animated creeps into TDTK.

So if you have TDTK, here is a step by step guide on how to add animated creeps into your game in Unity. If you don't you can get it here.

1) In the Hierarchy tab, right click and click "Create Empty" to create an empty game object.

create empty object in Unity 3d

2) In the inspector tab, Change the name of the empty game object to something recognisable (the name can also be changed in the hierarchy tab).

name the object TDTK unity

3) In the inspector tab, click on "Add Component" and search for Unit, click to add the "Unit Creep" script.

add the unit creep script in TDTK unity

4) In the inspector tab, click on "Add Component" and search for Unit, click to add the "Unit Creep Animation" script.

add the unit creep animation in TDTK unity

5) Add a colider. You need to add a colider for your creep for it to work properly, because the towers need to hit something. To do this just click on the add component for the new game object you created and click physics>colider.

6) Now you are ready to add the mesh, but before you add it, you need to check it has been imported correctly. Find your mesh in the Project tab (if you have not yet imported it, now is the time to do it), click on your mesh and check the following:
- Under the Rig section (click the 'Rig' button) you should probably set the animation type to humanoid (as long as your mesh walks on two legs) and then click apply. This will set it up for use with mecanim.

importing as humanois to create avatar TDTK unity

- Under the animation rig, you need to make sure any animations which should loop are set to do so. For example, running should be a looping animation because it repeats as the charter moves, so to should the 'walk' animation, but obviously the 'die' animation will only be played once. The make sure the animation which need it are looped, under the animation section for the import settings of the mesh,  click on each clip in the 'clips' box and put a tick next to "Loop Time". Idle should also be looped.

loop settings in mesh animation unity

7) Now that you have the mesh settings correct, drag the mesh to be a child of the Empty game object you created (drag and drop it on the game object in the hierarchy tab).

drag to create mesh as child TDTK unity

8) Now click on the triangle in the game object in the Hierarchy tab to expand it. Click on the mesh (the first thing underneath the game object) and note the animator section in the inspector. It should have an aviator set but no controller (if there is no avatar, check the import settings of you mesh as describe above). In the creep section of animation for TDTK (TDTK/Animation/Creep), drag the "CreepAnimationControllerTemplate" into the controller slot in the inspector (under the animator component).

animation controler location TDTK unity

creep animation controler settings TDTK unity

9) Set you animations in the "Unit Creep Animation" section of the game object. Choose 'type' = "Mecanim", the animator can stay as "none" but you must choose which clip to play for each of the four types of animation, simply click the circle selector (the little circle with a dot in it) next to the animation and choose the type opt animation the suits. NOTE! make sure that you choose the animation that was created for this mesh, you can check this by looking at the path shown at the bottom of the window when a clip has been selected.

unit creep animation settings TDTK unity

10) Make sure you have a prefabs folder in your project tab and simply drag the game object into it. Congratulations, you now have a prefab ready to add to the CreepEditor

11) In unity, click on tools>TDTK>Creep Editor  Drag your newly created prefab.

drag to create prefab TDTK unity

11) Drag the prefab into the "Add new creep" slot of the TDTK.UnitCreep window. Your new creep has now been added and is now part of your game.

drag prefab to TDTK creep editor unity

Check that the animation component is set and all the clips are correctly chosen at the bottom of the details for your now creep. You can now also name it (the name which will appear in game) and add an icon.

animation component in TDTK creep editor unity