← Pixel Dreamer Studio

Keep attack presses made just before the swing ends

Remember the press for a short time and start the next swing as soon as the character is free.

Checking is_action_just_pressed() only while the character is not attacking throws away every press made while a swing is still playing, and players press a little early. In our Godot 4.7 test, pressing every 0.3 s during 0.4 s swings started only 5 swings from 10 presses. Remember the press for 0.2 s and start the swing when the character is free: 8 of 10, 0.088 s after the press on average.

The code

Call press() from your input code when attack is pressed, and tick(delta) every frame. Wherever the character becomes free to attack, idle or at the end of a swing, start the next swing if consume() returns true. One press starts one swing at most.

extends Node
## Remembers an attack press for a short time, so a press made just before the
## current swing ends still starts the next swing.
## Call press() from your input code and tick(delta) every frame.
## When the character is free to attack, start a swing if consume() returns true.

@export var buffer_time := 0.2  # seconds a press is remembered

var _left := 0.0


func press() -> void:
	_left = buffer_time


func tick(delta: float) -> void:
	_left = maxf(_left - delta, 0.0)


func consume() -> bool:
	if _left > 0.0:
		_left = 0.0  # one press = one swing
		return true
	return false

What we measured

A 0.4 second swing at 60 fps, with presses at set times. Two runs with the same numbers.

Why it happens

A swing takes time, and players press for the next one before it ends. If those presses are dropped, the game feels like it ate the input. A short buffer bridges that gap. Keep it short: a press made long before the character is free was probably not meant for the next swing, and a long buffer can make the character keep attacking after the player stopped.

What to change

Hit each enemy once per swing: sword hitbox that hits each enemy once. Make the hit land harder: hit stop. A parry that works the same at any frame rate: parry window in seconds.

Ready-made slashes: Japanese VFX for Godot 4 has 37 presets, including a Katana Slash crescent with sparks, kitsune fox fire, torii portals, ofuda barriers and sakura petals.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Japanese VFX for Godot 4 has 37 ready-made Japanese effects, including a Katana Slash crescent with sparks, kitsune fox fire, torii portals, ofuda barriers and sakura petals.

More how-tos for Japanese VFX for Godot 4: A sword hitbox that hits each enemy once per swing

More how-tos: Game feel