Making character face directions with WASD

Hello, I’ve been trying and searching for an answer for 2 days, but I haven’t been able to find one. I’m experimenting by making a top view perspective, I made the most basic move blueprint (the one from the tutorials), but that only makes you move, not face the direction you’re going. Every tutorial I’ve seen only shows you how to turn around using mouse controls. I tried changing stuff myself, but the most I’ve gotten it to turn is by checking ‘Orient Rotation to Movement’, which only makes it turn slightly to the left or right, not completely. I turned off ‘Use controller rotation yaw’ and it kinda worked, except that it makes the character rotate infinitely.

Is there any way, for the love of everything that is good, to use keyboard controls to make the character face the direction you’re going without using mouse controls?

this is for you

1 Like

EDIT: Looks like I took too long to answer and there is a simpler solution, but, I’ll leave this here

I am assuming you’re making something resembling old zelda games where you walk where you’re facing, except in this case, in up to 8 directions, so I apologize if I’m misunderstanding. If you want only 4 directions (north east south west, but not northeast, southwest, etc) you can do this easily by like this (http://puu.sh/idZHN.jpg) once you figure out which key/yaw amount is correct, it’ll be some multiple of 90, just guess and check. If you want 8 directions I can think of two ways to do this, I can’t check the math/algorithm so I might be wrong but maybe this will help you get started.

One way is by setting your control rotation’s yaw to be a function of the actor’s velocity, I think your X and Y and if they are positive or negative should correspond with the direction you want to face, this might take some guessing and checking and could be subject to some glitchiness if the character is being bumped around or other issues which could be worked around with more logic.

The other way would be to keep track of which buttons the player is pressing and force their rotation on inputs. For example, you could make 4 bools, one for each direction, and set them to true when pressing the corresponding key (such as W = north) and false when releasing it. Then for each key input you would make branches, check if the opposing key is being pressed, and if not, check if the adjacent key is pressed and set the rotation accordingly. This will seem fairly bulky since you’ll need this logic potentially on all four key presses and you’ll have to consider 4 cases per key (only W, WA, WD, and WS for example) but should mean the player is always in control of their facing direction even if they get knocked around by enemies or what have you. I know this is pretty vague and there is probably a simpler way to do this, but, it should solve your problem.

This works almost perfectly, thank you. For some reason, the character resets back to it’s original rotation value (which is looking north). Is there something else I can add to the code, or do I have to tick/untick some stuff in the details?

EDIT: Nevermind, I turned off ‘Use controller rotation yaw’ and now it stays in place. Now all I need to do is make it turn around smoothly and not instantly.

EDIT 2: Okay, I figured the whole code out. Thanks for your help!

I appreciate you took your time, though. So, thank you

Can you please share your final BP?

That was my problem as well. Thanks.

had to comment on this and thank you for saving my life with this