- Home /
Changing variable when player is moving
Hey guys! I am trying to get a variable to become true whenever they move. I did this by simply checking if the player is pressing the arrow keys. For some reason, the variable doesn't become true when going horizontal. Anybody know why?
if(isCreeping == false && Input.GetAxis("Horizontal") > 0)
{
MakesSteps = true;
}
else
{
MakesSteps = false;
}
if(isCreeping == false && Input.GetAxis("Vertical") > 0)
{
MakesSteps = true;
}
else
{
MakesSteps = false;
}
Answer by Borzi · Dec 31, 2013 at 06:01 PM
if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
{
CheckGround();
}
Kinda worked it out later :P
Answer by blueteak · Dec 31, 2013 at 05:57 PM
Use Absolute value of the Horizontal input.
Mathf.Abs(Input.GetAxis("Horizontal")) > 0
The input can be positive for one direction, and negative for another (left/right). Also, I would remove the Vertical one, because you probably don't want to make footsteps while jumping or falling.
Answer by IgorAherne · Dec 31, 2013 at 06:02 PM
lol ! :D
Well, when you are pressing a forward button, makesSteps is true, but the next moment it becomes false as soon as the function reads the else statement, where the same variable becomes equal to false (lower, in the vertical statement)
To fix the problem, instead of else put else if( ! Input.GetAxis("horizontal or vertical")){ makes steps = false;}