Godot 4.3
Hello! I have been trying for hours and nothing seems to fix this, I’m trying to make it where if the Sprint button is being pressed, then the attack button is disabled, I’m not sure how to do this. Could someone please help?
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("attack2"):
if Input.is_action_just_pressed("run") == true:
$"../Knife".queue_free()
if Input.is_action_just_pressed("run") == false:
$"../Knife".show()
$"../Knife".queue_redraw()
if $"../Animations".flip_h == true:
$"../AnimationPlayer".play("Knife_(LEFT)")
if $"../Animations".flip_h == false:
$"../AnimationPlayer".play("Knife_(RIGHT)")
if $"../AnimationPlayer".animation_finished:
$"../Knife".hide()
Have you tried something like this?
var can_attack := true
func sprint_pressed() -> void:
can_attack = false
# Do sprint stuff
can_attack = true
func attack_pressed() -> void:
if not can_attack: return
# Do attack stuff
I didn’t create this. But, I see about 800 posts a month about how to press a button and disable another button at the same time.
- Can you post the entire script here.
- Share a whole project repository, so we can finally finish this project
- At least post what type of a node this is a script for
I get there are bad questions. Then there’s a level of horror questions.
it looks something like this.
can you explain the concept here.
visualize with me.
is the attack button the same as run button
or are they separate buttons
var button_presumed = false
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("attack2"):
if button_presumed == true:
attack()
else:
return
if Input.is_action_released("run"):
$"."./Knife".queue_free()
button_presumed = true
if Input.is_action_pressed("run"):
$"."./Knife".show()
$"."./Knife".queue_redraw()
if $"."./Animations".flip_h == true:
$"."./AnimationPlayer".play("Knife_(LEFT)")
if $"."./Animations".flip_h == false:
$"."./AnimationPlayer".play("Knife_(RIGHT)")
if $"."./AnimationPlayer".animation_finished:
$"."./Knife".hide()
button_presumed = false
Does your Input Map use the same key but with Shift or Control options? I found in my project that it is unintentionally possible to get my input code to respond to Left when I pressed Shift-Left.
In Project Settings / Input Map you can specify how the additional options are used, the images below are from two different settings but both using the Left Arrow, one with Shift and one without:-
In your input code you can specify close adherence to the e.g. Shift option by using
if Input.is_action_just_pressed("keyname", true):
rather than this which will use the default false value for the exact_match parameter
if Input.is_action_just_pressed("keyname"):
Documentation is at Input — Godot Engine (latest) documentation in English
Hope this might help,
Martin