Saturday, May 24, 2014

Introducing the CraBot unit

This post is a small making-of about the first enemy unit we have in the game. There's also some ramblings about tools and workflow.

"Crabot is a standard enemy unit, a security robot that is found patrolling in various locations around the bases and labs of Island Delta. These crab-like contraptions use their claws with deadly accuracy and efficiency against all intruders."

The model and animations

CraBot was originally modeled and uv mapped in MODO 701. I personally like the modeling & uv mapping tools with some great 3rd party scripts to ease the process:

The model was then thrown into Blender for rigging and animation because I feel that Blender is still ahead of MODO in these aspects. Also, I've been using Blender since the early 2001 so I'm quite comfortable with it.

It can get tricky to optimize the mesh because of all the round shapes. The mesh consists of 1127 vertices and 1938 tris. There's still room for optimization but it's getting there and we've had no performance issues so far.

The rig has 32 bones which is quite a high number due to all the six limbs, but luckily there's not going to be huge swarms of CraBot's anywhere in the game. On the animation side, CraBot currently has 10 different animations and more will be added later when needed. Here's a video showing the animation states:



Unity and Mecanim

This unit was the first animated model in the game. Getting animated models properly from Blender into Unity was something that we learned during the process (it's still a continuing process).

Blender .fbx export settings
Import scale is the first thing to consider. The way to do this correctly is to export the .fbx from Blender using the default scale of 1.0 in the export settings and then tweak the import scale in Unity to get correct scale. In this case, the ideal import scale turned out to be 0.3.

There was one issue in particular that we had to figure out how to deal with: because in Blender's axis system the z is pointing up and not towards the horizon as it is in Unity (and almost every other 3d program in the world), all models come into Unity flipped -90 degrees on the X-axis. It will cause problems when you want to parent other game objects inside the rig hierarchy in Unity since they will inherit the -90 degree rotation. It's something to keep in mind and work around with.

It's quite easy to create connections and blends between different animation states with Mecanim, and the ability to add event triggers and parameter curves to animation clips is very nice.

The connection chart can get a bit messy though, and the connection lines often tend to form a pentagram for some reason. Still learning...

As for the behavior, CraBot uses Unity's NavMesh system for pathfinding and has several custom scripts for other actions including patrol, investigate and attack states. Unity supports different scripting languages but our choice is C#. CraBot's behavior patterns are constantly fine tuned and new abilities are planned to further improve the unit, such as the ability to hear and investigate suspicious sounds.