I have two KinematicBody2D nodes with circle collision shapes. Body1 stays in one spot calling move_and_collide(Vector2.ZERO)
every _physics_process
. Body2 is initially colliding with Body1 and then every _physics_process
calls move_and_collide
to move away from Body1.
If Body1 detects a collision it calls get_tree().set_deferred("paused", true)
, waits one second, then unpauses. It then enters an infinite loop, detecting a collision on every physics step, even as you can see Body2 moving farther and farther from Body1.
If I comment out the line that pauses the scene tree, only 1 collision is detected and the scene works as expected.
Am I missing something or is this a bug? Any workaround?
Below is the code for Body1:
extends KinematicBody2D
func freezeFrame(duration):
get_tree().set_deferred("paused", true)
yield(get_tree().create_timer(duration), "timeout")
get_tree().paused = false
func _physics_process(delta):
if move_and_collide(Vector2.ZERO):
print("collided!")
freezeFrame(1.0)
EDIT: Here's a link to the example project. Please enable Visible Collision Shapes in the Debug menu. If you run the project you'll see the infinite loop I'm talking about. If you comment out the line that paused the tree it runs perfectly.