Replacing UDK’s ‘BlendByDirection’

If you have Dream version 0.4.4 (Will be fixed in later versions) you will notice that when you change Howard’s direction he moves his feet to the left/right beforehand.

This has been an issue for some time now. In UDK you create the characters movements using an AnimTree, which is a collection of nodes/instructions on how the character should respond. One of the Nodes that detects which way the Pawn (Character Piece) is moving, AnimNodeBlendDirectional.

The reason Howard “jumps” a little with his feet is because the Pawn is always facing forward. The AnimNodeBlendDirectional is meant for use with 3rd person cameras, as the Forwards, Left, Right and Backwards nodes are really asking which way the character is facing. If Dream was a 3rd person adventure game, this node would be fine.

The image below shows the Node set up. You can see me scrubbing the node from walking forwards to backwards, and as it decides this based on the pawns degree of rotation, you can see it scrubbing through the ‘right’ animation. If I had scrubbed the timeline backwards it would have gone via the ‘Left’ animation.

AnimTree_Walk_Old

 

This image shows the node running in game.

WalkCycleOld

 

To solve this I had to create some script, then reference the custom variables inside the AnimTree.
Firstly in my Pawn class, I added the following 2 variables.

var float         howardwalkMultiplier, howardstrafeMultiplier;

Then inside the tick function I added a local variable and a direction clamp for the Velocity, so moving backwards would push the float into the negative, but it would clamp at -1. Forwards would move the number in a positive direction, clamping at one. So here we are just assigning the Velocity value at a clamped point.

function Tick(float DeltaTime) {

local float newDirMultiplier;
super.Tick(DeltaTime);

newDirMultiplier = Vector(Rotation) dot Normal(Velocity);
FClamp(newDirMultiplier, -1.0f, 1.0f);
howardwalkMultiplier = Lerp(howardwalkMultiplier, newDirMultiplier, 0.1f);

newDirMultiplier = Vector(Rotation) dot (Normal(Velocity) cross vect(0,0,1));
FClamp(newDirMultiplier, -1.0f, 1.0f);
howardstrafeMultiplier = Lerp(howardstrafeMultiplier, newDirMultiplier, 0.1f);

}

After this, it was simply a matter of adding 4 AnimNodeBlendByProperty’s into the Anim Tree, referencing the variable names and inputting the clamps into the nodes.
NewWalkDir

 

So in the top section, clockwise, we have howardwalkMultiplier, with clamped nodes of Min -1.0 and Max of 1.0 – This finds the clamped value and runs Forwards or Backwards nodes.
If Backwards we have another node, howardwalkMultiplier, with clamped nodes of Min of -1.0 and Max of 0. -1 Is moving backwards on the Y axis so that runs the backwards animation, 0 is no movement (Moving in the X or Z) – so goto strafe
The howardstrafeMultiplier node now checks the X axis for Min -1.0 and Max 1.0 – then run strafe animation Left if -1.0 and Right if 1.0
The Forwards node underneath is similar to the backwards node above it, but as you probably guessed, the Min clamp is 0 and the Max clamp is 1 this time.

Here are the after results;
NewWalkCycle

 

Not too sure if this would be helpful to you or not, but I found it interesting, so I thought I should update my blog with it 🙂