# Unity - Invert Movement Direction

I am currently developing a 2,5D Sidescroller in Unity (just starting to get to know it).

Right now I added a turn-script to have my character face the appropriate direction of movement, though something with the movement itself is behaving oddly now.

When I press the right arrow key, the character moves and faces towards the right. If I press the left arrow key, the character faces towards the left, but "moon-walks" to the right.

I allready had enough trouble getting the turning to work, so what I am trying is to find a simple solution, if possible without too much reworking of the rest of my project. I was thinking of just inverting the movement direction for a specific input-key/facing-direction.

So if anyone knows how to do something like that, I'd be thankful for the help.

If it helps, the following is the current part of my "AnimationChooser" script to handle the turning:

    Quaternion targetf = Quaternion.Euler(0, 270, 0); // Vector3 Direction when facing frontway
Quaternion targetb = Quaternion.Euler(0, 90, 0); // Vector3 Direction when facing opposite way

if (Input.GetAxisRaw ("Vertical") < 0.0f) // if input is lower than 0 turn to targetf
{
transform.rotation = Quaternion.Lerp(transform.rotation, targetf, Time.deltaTime * smooth);
}
if (Input.GetAxisRaw ("Vertical") > 0.0f) // if input is higher than 0 turn to targetb
{
transform.rotation = Quaternion.Lerp(transform.rotation, targetb, Time.deltaTime * smooth);
}


The Values (270 and 90) and Axis are because I had to turn my model itself in the very first place to face towards any of the movement directions.

• You're only showing us the rotation code, but describe a problem with the movement code. – MichaelHouse Jun 7 '14 at 14:13
• not sure if there really is much movement code. I took that pill-looking character-preset "First Person Controller" with the Character Motor and the FPS Input Controller... I set my movement in the Input Settings of the Projekt and that basicly settled the movement itself. Without the rotation script, the character moves left and right just fine, though without turning to face the movement direction. With the rotation script I have the problem I stated above. In other words, whatever causes the problem is probably somewhere in there. – m41n Jun 7 '14 at 16:07

Well, I solved it myself now. After a lot more searching I found just the spot to reverse the movement.

I went to the pre-made FPSInputController to the line where it says:

directionVector = directionVector * directionLength;


And instead changed it to this:

        if (Input.GetKey("d") || Input.GetKey("right"))
{
directionVector = directionVector * directionLength;
}
if (Input.GetKey("a") || Input.GetKey("left"))
{
directionVector = -directionVector * directionLength;
}
else
{
directionVector = directionVector * directionLength;
}


And now the character moves as he is supposed to.