Fix para los items que no caen
This commit is contained in:
1 parent
1e70a99224
commit
5012879591
9 files changed
+144
-1468
No files matched your search
+12
-2
@@ -45,8 +45,18 @@ static func roll_drop(drop_table: PickupDropTable) -> Array[PickupData]:
|
||||
|
||||
|
||||
static func spawn_drops(drops_data: Array[PickupData], parent: Node, position: Vector2) -> void:
|
||||
# Death can happen inside a physics collision callback. Adding a new Area2D
|
||||
# immediately at that point is unsafe: defer its entry into the scene tree.
|
||||
# Set its local position first so it never briefly enters at the origin.
|
||||
var local_position: Vector2 = position
|
||||
if parent is Node2D:
|
||||
local_position = (parent as Node2D).to_local(position)
|
||||
|
||||
for data in drops_data:
|
||||
if data == null:
|
||||
push_warning("A drop was requested without PickupData.")
|
||||
continue
|
||||
var pickup := PICKUP_SCENE.instantiate() as Pickup
|
||||
pickup.pickup_data = data
|
||||
parent.add_child(pickup)
|
||||
pickup.global_position = position
|
||||
pickup.position = local_position
|
||||
parent.call_deferred("add_child", pickup)
|
||||
@@ -3,6 +3,10 @@ class_name Pickup
|
||||
|
||||
signal picked_up(pickup: Pickup, data: PickupData)
|
||||
|
||||
# Give players a moment to see the item before it can be collected. Otherwise
|
||||
# a close-range kill may immediately pick it up inside the player's collision.
|
||||
const PICKUP_GRACE_SECONDS: float = 0.75
|
||||
|
||||
@export var pickup_data: PickupData
|
||||
@export var fall_speed: float = 150.0
|
||||
@export var bob_amplitude: float = 4.0
|
||||
@@ -27,6 +31,15 @@ func _ready() -> void:
|
||||
placeholder.color = pickup_data.color
|
||||
start_y = position.y
|
||||
body_entered.connect(_on_body_entered)
|
||||
_enable_collection_after_delay()
|
||||
|
||||
|
||||
func _enable_collection_after_delay() -> void:
|
||||
# The scene starts with monitoring disabled. Enabling it after the initial
|
||||
# grace period also avoids overlap signals during creation in a physics tick.
|
||||
await get_tree().create_timer(PICKUP_GRACE_SECONDS).timeout
|
||||
if is_inside_tree():
|
||||
monitoring = true
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
size = Vector2(16, 16)
|
||||
|
||||
[node name="Pickup" type="Area2D"]
|
||||
z_index = 2
|
||||
collision_layer = 0
|
||||
collision_mask = 2
|
||||
monitoring = false
|
||||
script = ExtResource("1_pickup")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
|
||||
Reference in new issue
Block a user