#Input.is_action_just_pressed("KEY") returning false when key is pressed.

7 messages · Page 1 of 1 (latest)

daring trout
#

I am reworking my charater movement and decided to create a state machine. I got the following states:

  • PlayerIdle
  • PlayerWalk
  • PlayerAttack

The states do basically what they are saying, the PlayerIdle is the init state and also when nothing is done or pressed, the PlayerWalk handles the move animation and the velocity and PlayerAttack makes the player perform a swing attack. In the PlayerIdle and PlayerWalk state, the button for attacking is checked so when you either stand still or walk around and press the Attack Button, the statemachine jumps to the Attack state and the player performs an Attack.

But, the wierd thing I came across which I cant figure out it the following:
When standing still and looking at any direction (So in the Idle State) the attack will be performed when pressing the attack button
When walking either left, right, up or down, same thing, the attack will be performed.
When walking diagonal only running up and left will make the Input.is_action_just_pressed("Attack") function return true (so it attacks). Going the other three diagonal direction the function returns false and the player will not attack.

My question: How does the function only returns true if the player walks up and left and not the other diagonal ways?

Code in the PlayerWalk State looks as follows:

var input_vector: Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")

if Input.is_action_just_pressed("attack"):
    if !player.isAttacking:
        player.FSM.change_state(self, "PlayerAttack")
        return    
                
if input_vector == Vector2.ZERO:
    player.FSM.change_state(self, "PlayerIdle")
else:
    updateWalkingAnimation(input_vector)
daring trout
#

Updated: If linked my attack button to something else, this made it work as expected, then I changed it back to the original button and now it works again... I cannot tell you why this bug happend but relinking the button helpend me out

sharp mango
#

If attack was assigned to SPACE on my PC and I'm holding arrow up and left, the attack may not be recognized

daring trout
#

Which warning box right above this paragraph?

#

I didnt know Keyboard ghosting was a think, thank you for explaning!