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.

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.

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

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?

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.

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.

Thanks man its working.