How to check the joystick direction relative to the Player character's facing direction?

In the Legend of Zelda: The Wind Waker for example, Link’s attack animation will depend on not only the direction the camera is facing relative to link but also the direction of input.

If the camera is facing link’s back, and the player holds forward on the joystick before the attack button, Link will thrust his sword forward.
VVVVV

If the camera is facing link’s left arm, and the player holds left before the attack, Link will again thrust in that direction.
VVVVV

Thrusting seems to be dependent on if the the joystick is being pointed in the exact direction link is facing on screen. Regardless where the camera is.

Now link also does a diagonal slash that seems to trigger if the joystick is pointed perpendicular to the direction he is facing.

If the camera is facing link’s left arm, and the player flicks the joystick up just before the attack button, Link will perform the diagonal slash.

The diagonal slash sequence is as follows:

https://forums.unrealengine.com/core/image/gif;base64

I would like to know of a method that could replicate these type of checks. I Imagine its probably easier than it seems but I’m still having trouble coming up with a solution. I’m still fairly new to unreal blueprints so keep that in mind. Anyways thanks to anyone who responds.​

Hi man,
sure!

First try using the draw debug line node.
Its a node to draw in 3d space .

Get the Char actor position and forward direction using the corresponding nodes.
Now try draw a line that start from the char pos, and end in ( Char pos + char forward *500 )
This should show you a line from the character to show the direction he is facing.

Now do the same with the camera,
if you are using a pawn or a camera inside the char or anything…
Find a reference to the camera and get the location and forward vector.
This time try to draw the line adding an offset otherwise it will be hard to see.
Like Camera location - 0,0,-200 (to start the drawing line under the camera itself, otherwise you see only 1 dot)

Now that you can see the two lines
You want to understand the relation between them and the attack direction so
Char-forward
Camera-forward
Direction attack
are the important things.

Basically you want to drop the attack direction on the character and see if is similar to the forward of the character.
If is it, do a trust attack ,
if is in the left, left attack…

An easy to understand trick is using a " scene component" inside the character. lets call it “Locator”
(you have to set the locator World location now… for more precision you should also remove the Z value of the vectors, setting it to 0 manually)
When you use Joystick right
You want to set the locator position to the Char pos + Camera right * 100
When you use Joystick Left
You want to set the locator position to the Char pos + Camera right * -100 ( it become left of 100 units )
Using Up
You want to set the locator position to the Char pos + Camera forward * 100
Using down
You want to set the locator position to the Char pos + Camera forward * -100 (backward)

Now your character have the locator in position and it will be on the left on the right, in front or in the back of char.
You can check the values of the " Local position of the Locator"
checking the X and Y will tell you where the attack should be and you can choose the right one!

You can also check if the vector Char-Locator is Egual to the front direction of the char , using a threshold.
and the cross product of these two vectors to know if is orto … but i thtink is more understandable the other way.

1 Like

In any game where you drive gameplay logic more complicated than just moving around via the movement input, it’s a good idea to capture it as a vector variable in a couple of contexts so it can be checked easily. This is what I do, before doing any actual movement application in my character:

Now I have two vectors I can call on any time I care about the input; one spits back the input vector ‘at the controller’ (i.e. up = forward no matter how we’re oriented in the world) and the other gives the same vector rotated into the world-space orientation based on the control rotation. Having easy access to that is a good thing.

In your case, all I would need to do is take the Input Vector World I’ve created (which tells me which world direction the player is tilting the stick, based on the camera orientation) and compare it to the actor forward vector. A simple dot product between those two would give me a float which tells me how closely aligned they are; if I wanted to be precise, a dot-product-acosd would give me a float which told me exactly how many degrees one was off from the other.

This is a slightly similar logic I use in my game; in my case, I don’t care about how the input differs from the way the actor is oriented, but I do care about the way it differs from his velocity (if the input direction is too far off the velocity direction, I engage a skid effect rather than continuing smooth motion), but the logic is effectively the same. Dot Product to ACosD gives me back a float which represents the angle, in degrees, between the two vectors. It’s not signed (that’s a bit more complicated) but if all I care about is how far one is from the other, this is the way to do it.

2 Likes