my character doesn’t calculate the backward direction correctly he keeps flicking sideways but never goes backwards
Could you provide a screenshot of your blendspace?
At a quick glance it looks like the classic -180/180 dithering issue,
When direction is calculated as 0 forward then backward can be 180 and also -180, and as the engine dithers between the 180 and -180 during the interpolation time the left/right blending will kick in, resulting in flickering between left/right backwards animations.
One way to avoid this issue is to use 2 blend spaces, one for forward direction, the second for backwards direction, with a transition between states based on forward input of either > 0 and 0 < with forward being the default, and when input is negative or < 0, then transition into backward blend space.
For the backward blend space you can base direction off input values instead of rotation, since you only have 2 inputs,
move forward and move right, move right needs to be a max of 5 different conditions,
When “move forward” is not equal to zero divide “move right” in half and set new float “Adjusted Move Right”
when “move forward” equals zero set new float “Adjusted Move Right” same as “move right” feed the “adjusted move right” float into the direction value for the blend-space this will give you strafe left, 45 degree left, straight, 45 right, strafe right, with your interpolation speed blending changes.
Here is a basic setup to give you an idea of what I mean:
There’s also a way to have strafing with a single blendspace. I’m kinda new to Unreal so not sure if this will cause problems further down the line but this works for me, I made a video about it might help you out.
To fix this and keep a single blendspace, what you need to do is have the backwards movement animation on direction 0 because the problem occurs when the movement is on -180 or 180 and the blendspace switches between them rapidly. You also need to have negative speed so you can distinguish between forwards and backwards movement. Once you get your usual direction and speed inside your animation blueprint, you need to run a branch with a condition of two InRange(float) that’s going to check if your movement is either around 180 or -180, make a new Direction variable and once the range check is true then set the new direction to be the old one divided by 0. If it’s false it should remain as the old direction. For the speed simply run another branch and one InRange(Float) that’s going to check if your direction of movement is between -100 or 100, if that’s true it means you are moving forwards so set your speed to be the same as the vector length. If it’s false means you are moving backwards so your speed should be multiplied by -1. Then in the end feed the new direction in the blendspace that’s in your state machine. And for the transition rules just use a speed check.