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:
You might need to normalize the vector before passing it to AddMovementInput.
answered Apr 02 '18 at 02:15 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here