Unreal Character movement and Blendspaces : UE4 Open World tutorials #2

This video demonstrates, how to add movement capabilities to our third person character for our open world game. For this, I'll use animation blueprints and animation blendspaces to smoothly interpolate a set of animations to match with the movement speed.

I'll explain the basic process in the video and only the things that require further explanations will be available in explained in this blog post.

The character will have 4 movement states, Idle stand, walk, run and sprint. Running-walking can be toggled and sprinting works only when the shift key is being pressed. The movement speed of the character will be varying from -600 to 800 in unreal units. With the use of 2D blendspace, we can get a unique animation by blending idle, walk, run, sprint animations downloaded from mixamo.

W.S.A.D movement input 

Movement input keys are defined in project settings -> input section. Also you can see/change input settings in DefaultInput.ini located in UnrealProjectFolder/Config.

These InputAxis event will be fired in each frame of the game when running, if the relevant key is down, it will return axis value 1 or -1 as defined in the input settings, otherwise 0. 

Calculating Movement Input Direction

Control Rotation : 
This returns the rotation of the character controller, According to our implementation, controller is facing whatever the direction currently player is seeing through the camera. 

Here we break the rotator into 3 components and get only the yaw component to calculate the forward and right vectors. That's because, we only need to apply movement input in the horizontal plain. Otherwise character will try to fly when we press W while looking at sky. 

Idle-Walk-Run-Sprint 2D Blendspace

Blend Spaces allow us to play blended animations based on the weights provided as the axis values. 

Calculating speed Forward and Speed Side

As shown in the above figure, dot product of any 2 vectors returns the length of the projection of first vector on the 2nd vector. Using the same theory, we can calculate the side and forward vectors

How to fix character sliding?

We can see some sliding as the character start to move and stopping. That happens because of the mismatches of the mvoement speed and footwork in blended animations. We can fix that by adjusting the placement of animation clips in blendspace and adjusting acceleration/de-acceleration values in character movement component. Also, you may have to change the playback speed of animation clips as well. 

Those are the points i thought would require further explanations. 
Thank you for reading the article, Feel free to raise any concerns here, or in youtube channel or in the following facebook page. 

Join my facebook game developers club here : gamedevelopersclub