- Home /
Having trouble with multiple keys for one command
I am creating a side-scrolling platformer whose controls are based on the movement of most fighting games. That means if the player jumps vertically up, there is no horizontal movement. I got that taken care of.
HOWEVER, to perform flips, players must press FORWARD and UP at "the same time" (to flip forward) or they can flip backward (by pressing UP and BACKWARD).
I attempted to do something like:
if(Input.GetAxis("Horizontal") > 0 && Input.GetAxis("Vertical") > 0)
but that doesn't work. I do not want to hard-code the input like this because what if I allow the player to change the controls later? Not every player will agree with my keybindings!
if((GetButtonDown("S") && GetButton("W"))
|| (GetButtonDown("W") && GetButton("S"))
{
// Do Flip!
}
S = move to the right
W = move up (jump)
THANK YOU IN ADVANCE!
Answer by blacksaibot · Apr 12, 2019 at 06:38 PM
I try to do this, but it only works if I have been pressing the horizontal movement control for a full second.
// ONLY MOVES IF GROUNDED
if (isGrounded)
{
// WHILE WALKING
if (Input.GetButton("Horizontal"))
{
// If told to jump while walking, flip
if(Input.GetButtonDown("Jump"))
{
// If walking away from target, flip backward
if (Input.GetAxis("Horizontal") == -1)
{
print("FLIP BACKWARD");
}
// If walking toward target, flip forward
if (Input.GetAxis("Horizontal") == 1)
{
print("FLIP FORWARD");
}
}
}
}