The question is answered, right answer was accepted
Axis moves player right but not left
I can get my player character to move right but he doesn't move left. The debug for move left is being called but the velocity doesn't seem to change like it does with "Right"
if(Input.GetAxis("LeftJoystickHoriztonal") < 0)
{
Debug.Log("Left");
vel.x = -walkSpeed;
}
if(Input.GetAxis("LeftJoystickHoriztonal") > 0)
{
Debug.Log("Right");
vel.x = walkSpeed;
}
else
{
vel.x = 0;
}
try something like :
vel.x = walkSpeed * $$anonymous$$athF.Clamp(Input.GetAxis("Horizontal"), -1, 1);
You just asked a similar question and I answered it. But you didn't mark it solved or anything, you just closed it and are now re-asking the same question, but now the code has typos. Horiztonal isn't even spelled correctly.
You're answer told me an alternative method for moving the character which wasn't the error. The error was caused by poor placement of the else statement which is why I didn't accept it.
Didn't have to bump and then close the question, just to write a duplicate question. Well anyways, glad you solved it.
Answer by Razputin · Nov 18, 2015 at 06:36 PM
got it working
if(Input.GetButton("Horizontal"))
{
if(Input.GetAxisRaw("Horizontal") < 0 )
{
Debug.Log("Left");
vel.x = -walkSpeed;
}
if(Input.GetAxisRaw("Horizontal") > 0)
{
Debug.Log("Right");
vel.x = walkSpeed;
}
}
if(Input.GetAxis("LeftJoystickHoriztonal") != 0)
{
if(Input.GetAxis("LeftJoystickHoriztonal") < 0)
{
Debug.Log("LeftStick");
vel.x = -walkSpeed;
}
else if(Input.GetAxis("LeftJoystickHoriztonal") > 0)
{
Debug.Log("RightStick");
vel.x = walkSpeed;
}
}
if(!Input.GetButton("Horizontal") && Input.GetAxis("LeftJoystickHoriztonal") == 0)
{
vel.x = 0;
}