From e2d29599ed330882e54fda3b902c84a8a7443b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Sat, 20 Sep 2025 17:46:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(Statemachine):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=89=A9=E5=93=81=E6=8E=89=E8=90=BD=E6=94=B6=E9=9B=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E7=9A=84=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整物品掉落状态机的收集逻辑,仅在玩家背包未满时才会被吸引和收集。移除冗余的条件判断,简化代码逻辑。 --- scripts/Statemachine/ItemDropped.gd | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/Statemachine/ItemDropped.gd b/scripts/Statemachine/ItemDropped.gd index 5640e03..205e681 100644 --- a/scripts/Statemachine/ItemDropped.gd +++ b/scripts/Statemachine/ItemDropped.gd @@ -26,7 +26,7 @@ func _physics_process(_delta): if is_instance_valid(targetPlayer): if collecting: linear_velocity = Vector2.ZERO - else: + elif targetPlayer.inventoryMax[item] > targetPlayer.inventory[item]: var direction = (targetPlayer.position - position).normalized() var speed = 1000.0 * targetPlayer.fields.get(FieldStore.Entity.GRAVITY) / ((targetPlayer.position - position).length() ** (1 / 3.0)) apply_central_force(direction * speed) @@ -35,9 +35,8 @@ func _physics_process(_delta): if targetPlayer.sprinting: apply_central_force((position - targetPlayer.texture.global_position).normalized() * targetPlayer.velocity.length() * 10) else: - if targetPlayer.inventoryMax[item] > targetPlayer.inventory[item]: - targetPlayer.collectItem(item, stackCount) - collect() + targetPlayer.collectItem(item, stackCount) + collect() func collect(): collecting = true