I’m trying to make an 8 directional dodge / roll but i don’t know how to set or make keybinds for example W (Forward) + A (Left) = Forward Left roll / dodge.
I already tried action mapping and using Booleans to check if W and A are pressed and if true then if player presses space while W and A are held then play montage and change local rotation to the desired direction but it became a bit of a spaghetti and it did work but eventually stopped working after a few rolls.
Instead of looking for which keys are pressed, you should look at the input vector, which is the computed desired direction vector based on all user pressed movement keys. This will also provide natural controller support.
When pressing roll key, use node GetPendingMovementInputVector or GetLastMovementInputVector (in character class). Pick the first one if it is not always zero, otherwise pick the other one (I can never tell in which cases the first one works specifically).
Once you have a dodge direction, you can pick the most-fitting animation. Having 8 animations seem to be a bit overkill, but if you want that regardless, you’ll have to compare the dodge direction versus the current character-facing direction. Considering everything should be planar, you can simply compare their Yaw. Normalize the difference (fn NormalizeAxis) then pick the best-fitting animation based on the result.
Example:
FVector DodgeDir = Character->GetPendingInputVector();
float Angle = DodgeDir.ToOrientationRotator().Yaw - Character->GetActorRotation().Yaw;
Angle = UKismetMathLibrary::NormalizeAxis(Angle);
// Angle is in [-180,180] range, divide by 45 and round to snap to the best fitting 8-directional direction
int32 AnimIndex = FMath::Round(Angle / 45.f) * 45;
switch (AnimIndex)
{
case 0:
// play forward
case 45:
// play forward-left
case 90:
// play left
case 135:
// play backward-left
case -45:
// play forward-right
case -90:
// play right
case -135:
// play backward-right
case 180:
case -180:
// play backward
}