I’m trying to make a bow that adds speed to a projectile while the left mouse button is pressed. After the mouse button is released, the projectile gets instantiated through a function.
I have the following code so far:
func _physics_process(delta):
$Bow.look_at(get_global_mouse_position())
if Input.is_mouse_button_pressed(1):
arrow.speed += 5
if Input.is_action_just_released("Shoot"): #Shoot is a left mouse button input
shoot()
doing this doesn’t seem to detect the mouse button getting released, though when I replace “Shoot” for another input it works just fine. What am I missing exactly? Any help would be appreciated.
if Input.is_action_just_released("Shoot"):
print("test")
to debug the the input itself also worked just ok. The problem is when I try detecting the mouse release inside of a condition that’s checking for a mouse hold. My guess is that the engine can’t handle both of those? If that’s the case, how would I fix it or work around it?
This doesn’t work. Because Input.is_mouse_button_pressed
is different from Input.is_action_just_released and Input.is_action_just_pressed
I don’t remember if there’s a way to decrease the amount of ticks because += 5 may be too much at 5 * 60 per second.
func _physics_process(delta):
$Bow.look_at(get_global_mouse_position())
if Input.is_mouse_button_pressed(1):
arrow.speed += 5 # or whatever bow pull back animation
if Input.is_action_just_released("Shoot"): #Shoot is a left mouse button input
shoot()
If you have any questions as to why, I can try to come up with a better explanation.
Code inside of a if statement will only run if the condition is true, including other if statements. It would check if you released the button only if you also pressed it in the same frame, which is impossible in Godot.
func _physics_process(delta):
$Bow.look_at(get_global_mouse_position())
if Input.is_mouse_button_pressed(1): # Button is held down!
arrow.speed += 5 # add 5 speed!
# no time has passed, functions run in one frame
# Button is held down so this cannot be true
if Input.is_action_just_released("Shoot"):
shoot()
There is no single frame where the button is both held and just released.