mirror of
http://junepve.top:3000/chicrobot/CINC.git
synced 2026-10-29 23:41:29 +08:00
fix(skill) 修复傀儡位移后与本体不在直线上的问题
This commit is contained in:
1 parent
63f38c59eb
commit
4644d9a838
1 file changed
+67
-17
@@ -600,25 +600,53 @@ export default class AttackSkillTestScene extends Phaser.Scene {
|
|||||||
const puppetX = this.puppet.x;
|
const puppetX = this.puppet.x;
|
||||||
const puppetY = this.puppet.y;
|
const puppetY = this.puppet.y;
|
||||||
|
|
||||||
// 获取本体拉近到傀儡一定范围内的坐标
|
// 计算本体与傀儡之间的距离
|
||||||
const closeX = this.puppet.x - 50 * Math.sign(this.puppet.x - yuange.x);
|
const dx = yuange.x - puppetX;
|
||||||
const closeY = this.puppet.y - 50 * Math.sign(this.puppet.y - yuange.y);
|
const dy = yuange.y - puppetY;
|
||||||
|
const distance = Math.sqrt(dx * dx + dy * dy);
|
||||||
|
|
||||||
// 傀儡移动到本体拉近后的位置
|
// 固定拉近距离阈值
|
||||||
this.puppet.setPosition(closeX, closeY);
|
const fixedDistance = 200;
|
||||||
this.puppet.setVelocity(0, 0);
|
|
||||||
this.puppet.clearTarget();
|
|
||||||
|
|
||||||
// 直接设置本体位置到傀儡原本位置
|
|
||||||
yuange.setPosition(puppetX, puppetY);
|
|
||||||
yuange.setVelocity(0, 0);
|
|
||||||
|
|
||||||
|
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;
|
break;
|
||||||
case 4: // 技能4:傀儡快速移动并拉本体
|
case 4: // 技能4:傀儡快速移动并拉本体
|
||||||
if (this.puppet && this.isControllingPuppet) {
|
if (this.puppet && this.isControllingPuppet) {
|
||||||
// 使用轮盘相对方向计算目标位置
|
// 使用轮盘相对方向计算目标位置
|
||||||
const maxDistance = 300;
|
const maxDistance = 200;
|
||||||
const distance = Math.sqrt(directionX * directionX + directionY * directionY);
|
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 targetX = this.puppet.x + normalizedX * maxDistance;
|
||||||
const targetY = this.puppet.y + normalizedY * 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.setPosition(targetX, targetY);
|
||||||
this.puppet.setVelocity(0, 0);
|
this.puppet.setVelocity(0, 0);
|
||||||
this.puppet.clearTarget();
|
this.puppet.clearTarget();
|
||||||
|
|
||||||
// 本体瞬间移动到傀儡附近
|
// 计算傀儡位移的方向向量
|
||||||
yuange.x = this.puppet.x - 50 * Math.sign(this.puppet.x - yuange.x);
|
const puppetDisplacementX = targetX - initialPuppetX;
|
||||||
yuange.y = this.puppet.y - 50 * Math.sign(this.puppet.y - yuange.y);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
@@ -959,7 +1009,7 @@ export default class AttackSkillTestScene extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
} else if (this.skillWheel.activeSkill === 4 && this.isControllingPuppet) {
|
} else if (this.skillWheel.activeSkill === 4 && this.isControllingPuppet) {
|
||||||
// 傀儡四技能:傀儡移动预览
|
// 傀儡四技能:傀儡移动预览
|
||||||
const maxDistance = 300;
|
const maxDistance = 200;
|
||||||
|
|
||||||
// 计算目标位置
|
// 计算目标位置
|
||||||
const targetX = this.currentlyControlled.x + normalizedX * maxDistance;
|
const targetX = this.currentlyControlled.x + normalizedX * maxDistance;
|
||||||
|
|||||||
Reference in new issue
Block a user