Unity Experiment : Rigging and Animation

9 Aug 2017

Two main goals this time: learn how Blender’s rigging and animation system works and get an animated model into Unity. I ended up doing two models, a simple hover bot (only two bones, no IK) and then a weird two legged walking bot with a head and neck.

Hover bot

Hover bot rigging

I've done some playing about with bones and IK before but never tried to do anything useful.

The hover bot has two bones, one for the body, and one for the hover ring. During the idle animation the body bobs in the air slowly, the ring follows but lags behind slightly, as if it’s trying to keep up with the movement of the main body.

When the bot starts moving the body rotates forward, followed by the ring. While it’s travelling the body bobs a small amount, with the ring oscillating much faster (almost like it’s being pushed about by the propulsion system).

When the bot stops the body tilts back to upright, followed by the ring, and then re-enters the idle animation.

Importing hover bot into Unity

One thing I did while I was making the animations, which turned out to be really useful, was to add a txt object in the scene and keeps notes of where the various animation start and stop. This made importing them into Unity a lot quicker as I could just enter the values rather then having to seek around in the scene looking for them.

The animation controllers interface took a bit of getting used to, knowing where to click to create/edit states and transition isn’t the most obvious but once you’ve worked it out it does make sense. In general, most of the options are on the states themselves, with the transitions holding the rest.

The only problem I had in my initial setup was the transition between the idle cycle and the speeding up one. By default transitions wait until the source state has completed its cycle before changing to the next, but as the idle animation was 2 seconds long this gave a long delay between asking to move and the animation starting.

The fix for this was to disable ‘Has Exit Time’ on the transition. This lets allows the transition to start at any point in the source cycle.

Another useful feature is the ability to change the speed of the animation directly in the controller. This lets you adjust the timing to match the game without altering the original animation. In my case, the speed up/down animation felt too slow so I just doubled the playback speed.

Walking bot

Walking bot rigging

This was a little more complicated, so I decided to use the IK solver in Blender. I didn’t know if I’d have to manually key-frame the bones for it to import correctly, but Unity doesn’t require that, so the bone+IK route is definitely the way to go.

To be honest, my rig isn’t very stable if you pull the foot target up beyond a certain point (the leg bends backwards at the knee), but isn’t a problem with the animation I want to do. I think I need to change the reference pose a bit to fix this so I’ll add that to my list of things to come back to and play around with more later.

The head and neck is slightly different to the legs as it has two IK solvers. The first tracks a head target causing the neck and head to move. The second only changes the bone the head is parented to, allowing you to have the head keep looking at something while it’s moving around.

The walk cycle is a little clunky, but I’m going to claim that’s because it’s a robot. Adjusting the animation curves manually, after getting the rough key-frames first, made the neck/head look a lot smoother and more natural, but this didn’t seem to work as well on the legs.

This is going to be something I’ll have to revisit, probably just working in Blender on animation.

Importing walking bot into Unity

As I’d already got animation states working on the previous model I just had a single walking state on this one. This test was more to do with seeing how the bones+IK animation worked.

As usual for Unity, things just worked. Apart from a few mistakes where I was coding in radians when it expected degrees it didn’t take much to have the leg bot walking around.

Wrapping up

I never really understood what the dope-sheet was used for in Blender, and how useful it is until now. If you don’t know what it does, it shows you the key-frames that are attached to objects and lets you select, delete, and copy them. This lets you take a reference pose from the beginning and copy it elsewhere to use as the starting point for something else.

Overall everything works fine. The walking bot’s animation could do with being smoother, but that’s the fault of the rigging and animation, not the system itself. As I said earlier, I’ll have to spend some time just playing in Blender doing animation to get better at this, but know I know how it imports into Unity and works I don’t have to worry about that in future.

This post has been taged as Unity