TowerJam 004 Setting the character up
2016-02-06 4:48 PM
I’ve been working on getting the character setup for movement and a simple attack combo system. This is my progress on the character at the time of writing this post.
This post was written in 3 parts as I progressed through the process of setting the character up.
To start off I’ve added 2 new action mappings to the project for light and heavy attacks. I’m very impressed with the action mapping stuff. It’s a nice way to add new actions to characters without locking yourself in too much at the code level. By that I mean when you want to define a new action mapping (aka input abstraction) you go to the project settings, choose the action mapping type and then give it a name. The name you give the mapping is what you use across the editor and the codebase to refer to the mapping.I’m not usually a fan of stringly typed stuff or using strings to reference data from code but I think in this case it’s actually a quite elegant solution as it allows easy extensibility and you can add new mapping without having to recompile the code portion of the project.
For instance to bind an light attack named “AttackLight”I would use this line of code in my character cpp file.
InputComponent->BindAction("AttackLight", IE_Pressed, this, &ATowerJamCharacter::AttackLight);
Where I’m referencing the action name I defined in the projects settings as well as a callback when the action event occurs. Inside the callback I set a bool called IsLightAttacking to true and later let the animation system use that to determine what animation plays.
The animation system is a little complicated at first but I’m now at the point where I can see the value in such a complex solution. It consists of many different components. Code, blueprint event graphs, special state machine graphs and state transition graphs. I’ve had some experience setting up characters in source and quake engines but this was quite different from an implementation standpoint. It took me about 3 hours of studying until I got comfortable with the tool. Compared to other tools I’ve used in the past is about the fastest ramp up time I’ve ever experienced.
Here is the starting point for learning about how character animation works in unreal.
Once I got the light and heavy animations and working I started looking at how I could do Devil May Cry style combo attacks where one attack animation can be cancelled into another attack animation. I started out by purchasing a package of sword animations from the Unreal marketplace. I had a 30$ credit from when Unreal 4 went free so I figured this was easily worth the money. The animations I used are available https://www.unrealengine.com/marketplace/sword-animset-pro
My first attempt to get it working as fast as possible so I can see something on a screen was both naive and ugly. If I was in the first attack in a combo I set it to allow switching to the next animation in the combo if the player pressed the attack button and the current animation was more than 50% complete. This caused the animation to change far too abruptly.
Now I want the animation to change abruptly. The term itself is called cancelling so I figured I had the right overall idea but I’m just approaching it too bluntly. So I went back to the unreal answer hub with specific questions which didn’t answer my questions but linked to the relevant documentation.
After reading the docs I determined that the next step to improving the animation transitions was to pick the transition points with more care than simply allowing it after the animation was more than 50% complete. For this I used animation notify events. Here’s a screenshot of them setup in the timeline. As you can see I have 4 custom events. The regions CanCancel and ResetCancel define the portion of the animation that the user can cancel into the next attack.
Here is a screenshot of where these events are used. This is inside the animation blueprints event graph.
At first I thought my animation notifies weren’t working correctly or were inaccurate. This was exacerbated by the fact animation notify events have a property called “montage tick type” which seemed to indicate the timing accuracy the event was fired. I chose the more accurate but also more computationally expensive “Branching Point” value. It turned out the biggest issue was that I don’t have an eye for animation and I had simply placed the animation notify at a badly chosen location in the animation timeline. I moved the notify events to earlier points in the timeline than my instincts initially thought was correct and everything started looking good.
Once I sorted out how to cancel an animation based on an animation notify event things were massively improved but I had accidentally set the blend logic transition property to “Custom” when I was playing with options and suffered a bug. The character model would T-pose for the duration of the animation transition. The temporary solution was to set the transition duration to 0.0 seconds. By removing the transition I removed the T-pose error. Ideally I’d like to have a slight transition between animations. It might turn out that it will look bad but I would at least like to see how it looks before deciding whether or not I want to use transition blending. Once I set the Blend Logic property back to “Standard Blend” everything was solved.
Once the blend was in I was BLOWN AWAY by how good it looked. In my head it seemed like animation blending couldn’t possibly yield such great results but I was dead wrong. This first attempt was with the linear blending mode. Here is the first combo results. The first animation is cancelling into the next one.
Finally to wrap it up I decided I would add 2 major “hub states”. This is to say I have 2 idle poses. A standard idle pose with the characters weapon sheathed and an attack stance which the player must be in to execute attacks. When in the attack stance the players movement speed is reduced.
Here is the state machine graph that shows a general overview of the flow between all the animations and animation states.