From 4644d9a838aeb7273e3af0463c7a5b818a4ccb10 Mon Sep 17 00:00:00 2001 From: wvellichor Date: Sun, 18 Jan 2026 01:12:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(skill)=20=E4=BF=AE=E5=A4=8D=E5=82=80?= =?UTF-8?q?=E5=84=A1=E4=BD=8D=E7=A7=BB=E5=90=8E=E4=B8=8E=E6=9C=AC=E4=BD=93?= =?UTF-8?q?=E4=B8=8D=E5=9C=A8=E7=9B=B4=E7=BA=BF=E4=B8=8A=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scenes/testScenes/AttackSkillTestScene.js | 84 ++++++++++++++++++----- 1 file changed, 67 insertions(+), 17 deletions(-) diff --git a/scenes/testScenes/AttackSkillTestScene.js b/scenes/testScenes/AttackSkillTestScene.js index 54fbaa8..c855a1b 100644 --- a/scenes/testScenes/AttackSkillTestScene.js +++ b/scenes/testScenes/AttackSkillTestScene.js @@ -600,25 +600,53 @@ export default class AttackSkillTestScene extends Phaser.Scene { const puppetX = this.puppet.x; const puppetY = this.puppet.y; - // 获取本体拉近到傀儡一定范围内的坐标 - const closeX = this.puppet.x - 50 * Math.sign(this.puppet.x - yuange.x); - const closeY = this.puppet.y - 50 * Math.sign(this.puppet.y - yuange.y); + // 计算本体与傀儡之间的距离 + const dx = yuange.x - puppetX; + const dy = yuange.y - puppetY; + const distance = Math.sqrt(dx * dx + dy * dy); - // 傀儡移动到本体拉近后的位置 - this.puppet.setPosition(closeX, closeY); - this.puppet.setVelocity(0, 0); - this.puppet.clearTarget(); - - // 直接设置本体位置到傀儡原本位置 - yuange.setPosition(puppetX, puppetY); - yuange.setVelocity(0, 0); + // 固定拉近距离阈值 + const fixedDistance = 200; + if (distance <= fixedDistance) { + // 如果距离小于等于阈值,直接交换位置 + // 记录本体当前位置 + const yuangeX = yuange.x; + const yuangeY = yuange.y; + + // 傀儡移动到本体位置 + this.puppet.setPosition(yuangeX, yuangeY); + this.puppet.setVelocity(0, 0); + this.puppet.clearTarget(); + + // 本体移动到傀儡原本位置 + yuange.setPosition(puppetX, puppetY); + yuange.setVelocity(0, 0); + } else { + // 如果距离大于阈值,执行拉近逻辑 + // 计算归一化方向向量 + const normalizedX = dx / distance; + const normalizedY = dy / distance; + + // 计算拉近后的位置(在本体到傀儡的直线上,距离傀儡fixedDistance的位置) + const closeX = puppetX + normalizedX * fixedDistance; + const closeY = puppetY + normalizedY * fixedDistance; + + // 傀儡移动到拉近后的位置 + this.puppet.setPosition(closeX, closeY); + this.puppet.setVelocity(0, 0); + this.puppet.clearTarget(); + + // 直接设置本体位置到傀儡原本位置 + yuange.setPosition(puppetX, puppetY); + yuange.setVelocity(0, 0); + } } break; case 4: // 技能4:傀儡快速移动并拉本体 if (this.puppet && this.isControllingPuppet) { // 使用轮盘相对方向计算目标位置 - const maxDistance = 300; + const maxDistance = 200; const distance = Math.sqrt(directionX * directionX + directionY * directionY); // 计算归一化方向向量 @@ -633,15 +661,37 @@ export default class AttackSkillTestScene extends Phaser.Scene { const targetX = this.puppet.x + normalizedX * maxDistance; const targetY = this.puppet.y + normalizedY * maxDistance; + // 记录傀儡的初始位置 + const initialPuppetX = this.puppet.x; + const initialPuppetY = this.puppet.y; + // 傀儡移动到目标位置 - // this.puppet.setTarget(targetX, targetY); this.puppet.setPosition(targetX, targetY); this.puppet.setVelocity(0, 0); this.puppet.clearTarget(); - // 本体瞬间移动到傀儡附近 - yuange.x = this.puppet.x - 50 * Math.sign(this.puppet.x - yuange.x); - yuange.y = this.puppet.y - 50 * Math.sign(this.puppet.y - yuange.y); + // 计算傀儡位移的方向向量 + const puppetDisplacementX = targetX - initialPuppetX; + const puppetDisplacementY = targetY - initialPuppetY; + const puppetDisplacementDistance = Math.sqrt(puppetDisplacementX * puppetDisplacementX + puppetDisplacementY * puppetDisplacementY); + + // 计算本体应该移动的位置(在傀儡位移的直线上,距离傀儡一定距离) + if (puppetDisplacementDistance > 0) { + // 本体与傀儡之间的固定距离 + const bodyDistance = 150; + + // 计算本体移动的方向向量(与傀儡位移相同的方向) + const bodyMoveX = (puppetDisplacementX / puppetDisplacementDistance) * bodyDistance; + const bodyMoveY = (puppetDisplacementY / puppetDisplacementDistance) * bodyDistance; + + // 本体沿着傀儡位移的直线移动 + yuange.x = this.puppet.x - bodyMoveX; + yuange.y = this.puppet.y - bodyMoveY; + } else { + // 如果傀儡没有移动,保持本体位置不变 + } + + yuange.setVelocity(0, 0); } break; } @@ -959,7 +1009,7 @@ export default class AttackSkillTestScene extends Phaser.Scene { } } else if (this.skillWheel.activeSkill === 4 && this.isControllingPuppet) { // 傀儡四技能:傀儡移动预览 - const maxDistance = 300; + const maxDistance = 200; // 计算目标位置 const targetX = this.currentlyControlled.x + normalizedX * maxDistance;