x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

alt text

Product Version: UE 4.7
Tags:
capture.png (170.1 kB)
more ▼

asked Jun 05 '15 at 11:09 PM in Blueprint Scripting

avatar image

Zefengel
26 3 4 8

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

this is for youalt text

controls.png (215.7 kB)
more ▼

answered Jun 05 '15 at 11:34 PM

avatar image

Mhousse1247
3.4k 152 28 317

avatar image Zefengel Jun 06 '15 at 12:39 AM

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!

avatar image Gnamics Feb 03 '16 at 04:20 PM

Can you please share your final BP?

avatar image kenmorechalfant Jul 25 '17 at 06:45 AM

That was my problem as well. Thanks.

(comments are locked)
10|2000 characters needed characters left

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.

more ▼

answered Jun 05 '15 at 11:55 PM

avatar image

VedgyB
226 14 13 35

avatar image Zefengel Jun 06 '15 at 12:53 AM

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

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question