![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | a7med |
i need to detect when all KinematicBody2D stop moving.
in KinematicBody2D script signal emitted when collision happened and yield used in root script with yield to wait for it to stop
KinematicBody2D script:
extends KinematicBody2D
var velocity
func _ready() -> void:
add_to_group("group1")
func _physics_process(delta) -> void:
var collision: KinematicCollision2D = move_and_collide(velocity * delta)
if collision:
emit_signal("stopped")
func move(v) -> void:
velocity = v * speed
root script
extends Node
func _input(event) -> void:
if event.is_action_pressed('ui_right'):
move_all(Vector2(1, 0))
if event.is_action_pressed('ui_left'):
move_all(Vector2(-1, 0))
if event.is_action_pressed('ui_down'):
move_all(Vector2(0, 1))
if event.is_action_pressed('ui_up'):
move_all(Vector2(0, -1))
func move_cells(direction):
set_process_input(false)
var x = get_tree().get_nodes_in_group("group1"):
x[0].move()
x[1].move()
yield(x[0], "stopped")
yield(x[1], "stopped")
set_process_input(true)
it works as far as first body registered with yield emits signal first
but if the second body registered with yield emitted signal first yield doesn’t end
what should i do to detect all in no specific order