From ffbd45412ea93fb3d24e7535be25fe35886d71f4 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: Sun, 14 Sep 2025 16:30:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Statemachine):=20=E5=B0=86=E5=86=B2?= =?UTF-8?q?=E5=88=BA=E9=80=BB=E8=BE=91=E6=8F=90=E5=8F=96=E5=88=B0=E7=8B=AC?= =?UTF-8?q?=E7=AB=8B=E6=96=B9=E6=B3=95=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将velocity处理和冲刺条件判断提取到新的sprintAi方法中,提高代码可读性和复用性 --- scripts/Statemachine/EntityBase.gd | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index 5e927e5..834765c 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -159,8 +159,7 @@ func _process(_delta): func _physics_process(_delta: float) -> void: animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.2)) if sprinting: - velocity *= 0.9 - if velocity.length() <= 100: + if sprintAi(): sprinting = false else: velocity = Vector2.ZERO @@ -354,6 +353,9 @@ func isPlayer(): # 抽象方法,实际上是一些钩子,不需要全部实现 func ai(): pass +func sprintAi(): + velocity *= 0.9 + return velocity.length() <= 100 func attack(_type: int): pass func die():