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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Adjusting movement input values according to character rotation.

I'm creating a isometric game where the camera is rotation is locked and follows the character. The character rotation follows in the direction to where the mouse is. This is done in C++. I'm trying to get my character movement to adjust according to the character rotation. As seen in picture 1, when the player is facing up "W" is forward, "S" is Backwards, "A" is left and "D"is right, But i want the input values to change when facing another direction.

If Yaw.Rotation is 0° then W value would be 1//forward, S value -1//backwards, A value -1//left, D value 1//right.

If Yaw.Rotation is 180° then W value would become -1//backwards, S value 1//forwards, A value -1//backwards, D value 1//forwards.

If Yaw.Rotation is 90° then W value would be -1//left, S value 1//right, A value -1//backwards, D value 1//forwards.

If Yaw.Rotation is 270° then W value would be 1//right, S value -1/left, A value 1//forward, D value -1//backwards.

Product Version: UE 4.19
untitled2.png (757.3 kB)
untitled.png (839.5 kB)
more ▼

asked Apr 02 '18 at 10:19 AM in C++ Programming

avatar image

8 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Just to clarify, you want WASD to always move the character up, left, down and right on the screen regardless of the character model's view direction?

APawn::AddMovementInput takes a world direction, so you need to base the value passed to it on your camera's world rotation. You just need to get a reference to your camera component and in your functions bound to movement input keys, determine the value passed to AddMovementInput as follows:

  • Forward Key: CameraComponent->GetForwardVector()

  • Backward Key: -1.f * CameraComponent->GetForwardVector()

  • Right Key: CameraComponent->GetRightVector()

  • Left Key: -1.f * CameraComponent->GetRightVector()

You might need to normalize the vector before passing it to AddMovementInput.

more ▼

answered Apr 02 '18 at 02:15 PM

avatar image

2.6k 95 41 111

avatar image Remesis Apr 02 '18 at 02:49 PM

Hi staticvoidlol Now looking at what i wrote i understand that I've may have made things more confusing and complicating than needed. What I'm trying to do is make ForwardVector relative to my characters current rotation. The camera is never rotated it is lock in rotation and only follows the character, if that makes any sense. For reference you can take a look at the game Ruiner. Adding link: link text

avatar image staticvoidlol Apr 02 '18 at 03:20 PM

OK so if we see the top, right, bottom and left of the screen as North, East, South and West respectively in the game world, and the character is currently facing North-East (based on where the mouse cursor is, what do you want to happen when the forward (W?) key is pressed? Should the character move North-East or North only?

avatar image Remesis Apr 03 '18 at 11:42 AM

Pressing W, would have the character run north only. Even if the mouse cursor was pointing north east the character would run north if you were to press W. Pressing W and D on the other hand, that would have the character move north-east. I'm still trying to implement what you posted first as that could very well be the answer to my question.

avatar image staticvoidlol Apr 03 '18 at 12:52 PM

Ok sure, yes if that's the behaviour you want then the original answer is how you would go about it. You are essentially determining the character movement direction based on the (albeit static) camera rotation as your desired movement direction is relative to the camera orientation.

avatar image Remesis Apr 03 '18 at 01:04 PM

Thanks man its working.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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