This is my personal project experimenting AI character body facing and head following feature in Unreal Engine 4. This project is derived from the Epic Game ActionRPG Project.

After a few days of digging through the source code of Epic Game’s ActionRPG project, I decided to play with some new abilities and AI building upon this awesome framework. First I want to test out some character facing behavior.

I first created a new enemy character with a bunch of animations downloaded from Mixamo, set up the animation blueprints, and also change my main character’s movement not oriented to the controller’s rotation.

GreatSwordBT.PNG

I use a behavior tree service node to constantly calculating the angle between the enemy character and the player by taking arccosine of the dot product between the enemy’s forward vector and player location – enemy location. When the angle exceeds a certain threshold, I play a root motion turning animation inside a custom blueprint task node.

It can be seen in the video that since every turn is fixed, the enemy can easily rotate too much or too less and look unnatural. After some debugging, I found that the turn animation rotates around 62 degrees each time. I then added a compensation according to the target (player) location and velocity to determine where the enemy should be facing after each turn.

Now that the enemy is facing directly toward the player after turning, I want to add head target following into this and see how it performs.

To show the effect of head tracking, I disabled the enemy’s rotation task, also slowed down the simulation rate so it can be seen easier.

And now, putting the target facing and head tracking together.

I still need to fix the jittering of the sword and tweak the head tracking speed a bit. But the overall behavior is more natural than before.

Next, I’m gonna try to play with some combat and character hands/arms IK when the weapon hits enemies.

Reference

Epic Games Action RPG

Head And Eye Look At Tutorial