[Unity 5] GetAxis("Horizontal") Causes player to move the opposite direction
http://answers.unity3d.com/questions/550988/my-movement-keys-are-opposite-to-actual-movement.html
My issue is exactly the same as in this thread. In my code, the player can rotate. this part works as desired. I can move vertical just fine, but horizontal movement makes me move the opposite direction (e.g. I move right when I press left) My code is this: using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour
{
private float speed = 1f;
public Transform playergraphic;
void Update()
{
ControllPlayer();
}
void ControllPlayer()
{
float horMovement = Input.GetAxis("Horizontal");
float vertMovement = Input.GetAxis("Vertical");
if (horMovement != 0 && vertMovement != 0)
{
speed = 3.0f;
}
else
{
speed = 1.5f;
}
transform.Translate(transform.right * horMovement * Time.deltaTime * speed);
transform.Translate(transform.forward * vertMovement * Time.deltaTime * speed);
//Player graphic rotation
Vector3 moveDirection = new Vector3(horMovement, 0.0f, vertMovement);
if (moveDirection != Vector3.zero)
{
Quaternion newRotation = Quaternion.LookRotation(moveDirection);
playergraphic.transform.rotation = Quaternion.Slerp(playergraphic.transform.rotation, newRotation, Time.deltaTime * 8);
}
//Player graphic animation
/*if (moveDirection.magnitude > 0.05f)
{
playergraphic.GetComponent<Animation>().CrossFade("walk", 0.2f);
}
else
{
playergraphic.GetComponent<Animation>().CrossFade("idle", 0.2f);
}*/
}
}
I have tried multiple "solutions, but nothing works. I can manually force input from keys, but this kills the option for a controller, and would make my investment in one for testing reasons a waste. Is this a issue in the latest build of Unity 5?
Your answer
![](https://koobas.hobune.stream/wayback/20220612084537im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I simulate the smoothness of the Input.GetAxis? 0 Answers
how to make the player move in only 2 directions? 0 Answers
Pressing the key once, moving up, down, left or right until meet the wall. 0 Answers
Assets/ballcontrol.js(3,5): UCE0001: ';' expected. Insert a semicolon at the end. 0 Answers