So I need to only receive -1, 0, or 1 as values from the Joystick (using a wired 360 controller at the time). When I use the following code with a keyboard it works exactly as intended, but when I use the thumbstick on the gamepad I get odd movement behaviors. When I tried adding Debug.Log(Input.GetAxisRaw(“Vertical”); the console showed it returning values between -0.2 and 0.2. I have no idea what is causing this and while I can think of a way around it it’ll take quite a bit of hard coding I’d rather avoid if at all possible.
float previousAxisStateX;
float previousAxisStateY;
float tileSizeX = 2f;
float tileSizeY = 1f;
Vector3 transPos;
void Update()
{
if (Mathf.Abs(Input.GetAxis("Horizontal")) > Mathf.Abs(Input.GetAxis("Vertical")))
{
if (previousAxisStateX == 0)
{
transPos = new Vector3(transform.position.x + (tileSizeX * Input.GetAxisRaw("Horizontal")),transform.position.y,transform.position.z);
transform.position = transPos;
}
}
else
{
if (previousAxisStateY == 0)
{
transPos = new Vector3(transform.position.x, transform.position.y + (tileSizeY * Input.GetAxisRaw("Vertical")),transform.position.z);
transform.position = transPos;
}
}
previousAxisStateX = Input.GetAxis("Horizontal");
previousAxisStateY = Input.GetAxis("Vertical");
}