holding down attack key repeats animation frame, how to prevent this in godot?

164 Views Asked by At

I have this grab and knee attack code which is part of a bigger script. The problem is I want it so that the player when grabbing the enemy that, when performing a knee attack that the player should knee attack on each key press. however in my code , holding down the attack key makes the player repeatedly knee attack. how do i prevent this , can anyone help? :

2

There are 2 best solutions below

0
curimania On

have a look into the different types of how to get user input. (releasing or presing a button)

or think about giving each action a timeout, that starts when it is performed and while its active it blocks the action.

there are multiple ways to conquer these kind of software problems and I think it is fun and a good challenge to come up with solutions. plus one does learn a lot when it comes to how to logically get into the actual problem and how to solve it.

0
Theraot On

I'm going to guess you are either working in _process or _physics_process and using Input.is_action_pressed, which will return true as every frame as long as the action is pressed...

In which case the easy solution is to change it to Input.is_action_just_pressed or Input.is_action_just_released which will only return true the frame the action is pressed or released respectively.

There might be other considerations (such as handling when the player is pressing the action too fast), but the above change should be sufficient to handle the common case.