Testing Movement and Animations

An important element of the adventure game genre to get right is the ability to move your character around the game world. We're going for a point-n-click style where the character will move to the position you clicked in the game world. We needed to start working on this early, and as soon as we had some geometry and a temporary main character to test with I started experimenting. The character we're using now is Liam, which we bought as inspiration for a possible character design direction.

We're using Unity3D's NavMesh to generate the walkable surface. This is a huge time saver and made the first task - walking on a flat surface - a breeze.

Walking on a flat surface is not very exciting though, so I introduced the stairs from Sindre's model used to test art style. The first test with stairs went okay. The character was able to walk up and down, although the animation was not a perfect fit.

Liam walking up the stairs

Liam walking up the stairs

Using a different animation than the regular walking animation as well as slowing down the movement speed a bit could help make it more natural. There is also some jumps during the ascent as the navmesh on the stairs are part steps and part slope.

We don't have a stair climbing animation yet, but to prepare to change animations when climbing stairs I need to test out some ways to know if our character is currently on stairs.

The stairs are marked with the 'stairs'-area, the rest is marked 'walkable'

The stairs are marked with the 'stairs'-area, the rest is marked 'walkable'

The first approach I've tested is to leverage NavMesh areas, which basically marks geometry as being one of multiple user defined areas (think water, swamp etc). It seems like the main use of this is to assign different costs to the areas, usable by the pathfinding to prefer some paths over others.

I needed to actually query the NavMesh Agent (our character) to figure out which area he's currently on. It turns out that this is neither easy nor perfect. I ended up with a solution to sample the current position of the character each frame to check which area the position belongs to.

With the mesh shown in the image, it jumped back and forth between the areas 'walkable' and 'stairs' multiple times when walking up or down the stairs. It became a bit more bearable when I applied an area mask to only check for stairs, but it still ended up finding 'walkable' once for a couple of frames on the ascent. If we're using a blend tree for our walk animations I hope it won't be a problem, as it will blend back too fast to catch.

The bigger issue is that this approach is not scalable. I need a sample of the position per area we want to check for. If we add e.g. four more areas, we need to sample the NavMesh five times per frame! I hope we can tweak the mesh so a single sample will be stable enough for our usage. The alternative is to add collision triggers each place we need an animation switch. I hope we don't have to end up with this, as I want to create a workflow that is as streamlined as possible when actually building the content.

Remark about NavMesh: I've heard about some more modern replacements for Unity's NavMesh such as NavMeshBuilder or NavMeshComponents, so I need to set aside some time to compare them soon. After all, this is the easiest time during the project to replace such a vital component.