Unity - Invert Movement Direction
- by m41n
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.