# Directional Evade/Roll/Dodge with Target lock on enemy

Hello people,

I am trying to get 4-way directional evade related to an enemy. I have a rotation lock-on system on the character that always updates his rotation towards the lock-on target.

Now I tried many ways to get character to roll to one of 4 ways (forward, right, left, back) depending on the player’s input.
One of the ways I tried is by saving player’s input by setting 2d vector (something I found on youtube) and then tried doing all kinds of weird maths to get it to work. I was trying to get input direction from -1 to 1 and then using booleans or some other logic to set a direction for the roll when button is pressed.

Could not find a tutorial with directional roll with target lock-on.

Isn’t Axis value already -1 → 1?

IMO the 2D vector from input is the way to go. Can you share that “some other logic” you tried with the 2d vector?

I have recently found a nice solution to this problem.

I use three known point while locked on:

1. Last Input Vector from CharacterMovement. This returns a vector that indicates the direction of movement.
2. Owner (player) location.
3. Target location (location of lock on target).

Then I converted these points into two vectors by subtracting and used the following formula to get the angle between them.

This gives my a range of -180 to 180 degrees, where the negative values indicated movement “to the left” of our current lock on target, 0 means towards the target and positive values “to the right” of the target.

Finnaly i just use branches to determine which montage to play depending on the angle.

This allows for more flexibility since you can also add more directions (8 way dodge) if you want.