Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | GamelandX |
Hi all, Im trying to throw a ball, sort of like angry bird, but I want to be able to launch the ball 3 times once it has stopped usually takes about 5 secs or less in theory, I tried adding a while loop but my game freezes when I run it, everything else works as intended.
extends RigidBody2D
var dragging
var drag_start = Vector2()
var launched = false
var tries = 3
func _input(event):
while tries != 0:
if event.is_action_pressed("click") and not dragging and not launched:
dragging = true
drag_start = get_global_mouse_position()
if event.is_action_released("click") and dragging:
dragging = false
launched = true
tries -= 1
var drag_end = get_global_mouse_position()
var dir = drag_start - drag_end
apply_impulse(Vector2(), dir * 5)
yield(get_tree().create_timer(5.0), "timeout")
launched = false
Could you share the project so i can see in detail? Shouldnt you use if instead of while? Because you need the code to be executed once per input, dont you?
p7f | 2019-01-13 14:07