State Machines

In this tutorial I will go over the steps necessary to create humanoid motion capture animations that can be used on state machines when creating character controllers in Unity:

State Machine Example

Unity Humanoid and state animations

A zombie character with a fencing foil and custom Sword attack animation state machine

In the following tutorial I am going to create the animation for a simple attack.

If you're not familiar with APS or Unity it is important to understand that Unity requires .anim files when working with the Mechanim system. APS can export motion capture as .anim files and other formats, in this tutorial I export mocap as .bvh to Blender, then from Blender as a .fbx to Unity. And using Unity to create individual .anim files for each attack by cropping out attacks from the full mocap.

Something important to keep in mind is that state machine controllers often require the root of each animation to be centered around the origin.

In APS you can enable the Bounds option which displays a room origin marker on the floor. This allows the user to always be sure to start a recording from the origin, and to not wonder around if recording multiple takes in a single animation!

Step1_TrackerFilters.mp4

Tracker Wobble (Filter)

Wobble reduction filter for fast-action motion capture

I recommend using the tracker low pass filters when recording mocap that includes jumps, dashes or stomping. As seen in this video wobbly feet trackers can be filtered to produce smoother looking motion capture.

Step2_StandAtMarker.mp4

World Origin Marker

Start recordings from the zero coordinate

State machine controllers often requires the root of each animation to be centered around the origin. For simplicity and best results it's recommended to enable the floor origin marker and ensure to always stand at the same location when starting a new recording.

Step3_EnableMirror.mp4

VR Mirror

Visualize the attacker

APS includes a VR mirror, and if you look to the top right of the mirror panel you'll see some buttons to lock and level the mirror. The mirror is helpful especially when creating short attacks to ensure each attack always attacks the attacker (aka, the other you in the mirror).

Step4_StartRecord.mp4

Start Recording

Record the attack sequences

For the tutorial I recorded a bunch of attacks in a single take, this video only shows one but in later videos notice how the mocap is simply one attack after another. This is so that later in Unity each attack can be cropped out as individual .anim files, and is much simpler than working with many separate mocap takes..

Step5_Review.mp4

Mocap Review

Make sure it all looks goods!

Once you've recorded a bunch of attacks it's a good idea to review the sequence in VR as the opponent would see the attack. This gives some idea of how realistic the final results will be.

Step6_ExportToBlender.mp4

Export To Blender

APS > Blender > FBX > Unity

This step involves simply exporting the mocap from APS to Blender, then from Blender as a .fbx so that the mocap can then be imported into Unity!

Step7_ExportFBXUnity.mp4

From Blender To Unity

Exporting the .fbx

Now that the mocap is imported into Blender all that's needed is to export as a .fbx to the Unity project folder. 

Step8_HumanoidAnimation.mp4

Humanoid Animations

Set the .fbx to type: "Humanoid"

In Unity it's necessary to set the .fbx to Humanoid for animations to work with Mechanim.  For this tutorial I used the included LuxVRM avatar, this avatar maps perfectly when the .fbx is set to "Humanoid", using other avatars may require manually mapping the bones, but that's it, you've got mocap in Mecanim !

Step9_CropAnimation.mp4

Crop The Animation

isolate a single attack from the full animation

As mentioned the .fbx contains a bunch of attacks including blocks and jabs, for this tutorial I am showing how to extract the .anim for only a single attack. In Unity's inspector look for the animation range handles and adjust the range until you have isolated just a single attack, then apply the range.

Step10_ExtractAnim.mp4

Extract the .anim

create a .anim file of just the cropped portion of the mocap

Now that you've applied the range for a single attack animation in the .fbx you can simply copy the relevant clip pressing Ctrl+D to extract the .anim file. First select the .fbx from the file browser and look for the mocap clip under the .fbx file, then select the clip and press Ctrl+D and a new .anim clip will be generated!

Step11_CreateState.mp4

Add new state

Add the .anim clip as a new state to Animator controllers

This tutorial does not go into detail about Animators and assume you already have a working Animator for your character. If so then it's simple to add the .anim we just crated by dragging and dropping the file into the animator editor window.

Step12_CharacterController.mp4

Final Results

Blending mocap w/ navigation and other attacks

And finally after a little tuning the animation speed and transition fade time it turned out okay. All in under 15 minutes!

Check back soon for more updates!

Thanks for reading ❤️