From 0f51e2e8d6b119ac3b136c228dc33d04b69befb6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 1 Oct 2023 00:05:15 +0200 Subject: [PATCH] Prevent spawn if coins would overlap --- spawner/spawner.gd | 2 +- spawner/spawner.tscn | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spawner/spawner.gd b/spawner/spawner.gd index 1cc21d5..be94ffb 100644 --- a/spawner/spawner.gd +++ b/spawner/spawner.gd @@ -4,7 +4,7 @@ class_name Spawner @export var target_parent: NodePath func spawn(): - if len($Area2D.get_overlapping_bodies()) > 0: + if len($Area.get_overlapping_bodies()) > 0: return var scene_instant = scene.instantiate() scene_instant.position=Vector2.ZERO diff --git a/spawner/spawner.tscn b/spawner/spawner.tscn index b97d4f9..399531f 100644 --- a/spawner/spawner.tscn +++ b/spawner/spawner.tscn @@ -2,8 +2,8 @@ [ext_resource type="Script" path="res://spawner/spawner.gd" id="1_xqfmg"] -[sub_resource type="RectangleShape2D" id="RectangleShape2D_xnebx"] -size = Vector2(100, 20) +[sub_resource type="RectangleShape2D" id="RectangleShape2D_p13i4"] +size = Vector2(16, 5) [node name="Spawner" type="Node2D"] script = ExtResource("1_xqfmg") @@ -12,11 +12,11 @@ script = ExtResource("1_xqfmg") wait_time = 0.1 autostart = true -[node name="Area2D" type="Area2D" parent="."] +[node name="Area" type="Area2D" parent="."] collision_mask = 4 -[node name="Shape" type="CollisionShape2D" parent="Area2D"] -position = Vector2(0, -15) -shape = SubResource("RectangleShape2D_xnebx") +[node name="CoinShape" type="CollisionShape2D" parent="Area"] +scale = Vector2(3, 3) +shape = SubResource("RectangleShape2D_p13i4") [connection signal="timeout" from="Timer" to="." method="spawn"]