this is my first time posting on here. I'm working on a game using the new Unity multiplayer networking solution. In summary, the issue is that the player is not moving as intended.
I am trying to take player input as follows:
Vector3 worldSpaceDir = new Vector3(Input.GetAxisRaw("Vertical"), 0, Input.GetAxisRaw("Horizontal"));
then convert it to the object space coordinates of the player character:
_inputDirection = transform.InverseTransformDirection(worldSpaceDir);
The issue I'm having is with a rotation of 0 or 180 the player moves as expected with the WASD inputs, however, at 90 or 270 all the inputs are flipped(A = right, D = left, W = backward, S = forward).
I found a question that is exactly my question but no one responded with an answer. The question is quite old now so I wanted to ask it again for more visibility.
Firstly, you are taking the
worldSpaceDir
wrong, it should be as followhere we take horizontal input as X and vertical input as Z, because in Unity Forward is pointed as Z and not Y.
Secondly, we do not need to use
InverseTransformDirection()
we just needTransformDirection()
something like followinghere we are telling unity to convert the
worldSpaceDir
that is relative totransform
(local direction) into a world space direction, so we might actually give a proper name toworldSpaceDir
.The following would work for you.