|
@@ -46,6 +46,7 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
protected registerEvent(): void {
|
|
|
EventDispatcher.instance.on(GameEvent.EVENT_GAME_START, this.decideAction, this);
|
|
|
EventDispatcher.instance.on(GameEvent.EVENT_GAME_START_EFFECT, this.decideAction, this);
|
|
|
+ EventDispatcher.instance.on(GameEvent.EVENT_STORM_RESURRECT, this.stormResurrect, this);
|
|
|
}
|
|
|
|
|
|
private initAIPlayer() {
|
|
@@ -146,13 +147,36 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
const targetTornado = otherCollider.node.parent.getComponent(TornadoComponent);
|
|
|
if (!targetTornado) return;
|
|
|
|
|
|
- const distance = Vec3.distance(this.node.worldPosition, otherCollider.node.worldPosition);
|
|
|
- if (distance < 0.2) {
|
|
|
- const isAI = targetTornado.ai;
|
|
|
- if (this.currentLv > targetTornado.currentLv && !isAI) {
|
|
|
- GameMgr.inst.isWin = false;
|
|
|
- // console.log(`AI 触发碰撞到:${targetTornado.name} isAI:${isAI}`);
|
|
|
- GameMgr.inst.setGameStatus(GameStatus.Revive);
|
|
|
+ // const distance = Vec3.distance(this.node.worldPosition, otherCollider.node.worldPosition);
|
|
|
+ // if (distance < 0.2) {
|
|
|
+ // const isAI = targetTornado.ai;
|
|
|
+ // if (this.currentLv > targetTornado.currentLv && !isAI) {
|
|
|
+ // GameMgr.inst.isWin = false;
|
|
|
+ // // console.log(`AI 触发碰撞到:${targetTornado.name} isAI:${isAI}`);
|
|
|
+ // GameMgr.inst.setGameStatus(GameStatus.Revive);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ if (event.selfCollider.node.name == 'RigibodyStorm') {
|
|
|
+ if (event.otherCollider.node.name == 'RigibodyStorm') {
|
|
|
+ const distance = Vec3.distance(event.selfCollider.node.worldPosition, otherCollider.node.worldPosition);
|
|
|
+
|
|
|
+ // 增加碰撞检测的容差范围
|
|
|
+ const collisionThreshold = 3; // 增加检测范围
|
|
|
+ if (distance <= collisionThreshold) {
|
|
|
+ // 添加额外的速度检查,确保不会因为速度太快而错过碰撞
|
|
|
+ const relativeSpeed = Math.abs(this.speed - targetTornado.speed);
|
|
|
+ const minSpeedThreshold = 5; // 最小速度阈值
|
|
|
+
|
|
|
+ if (relativeSpeed >= minSpeedThreshold || distance <= 1.5) { // 如果速度差够大或距离非常近
|
|
|
+ const isAI = targetTornado.ai;
|
|
|
+ if (this.currentLv > targetTornado.currentLv && !isAI) {
|
|
|
+ console.log(`AI 击杀玩家!!!`);
|
|
|
+ GameMgr.inst.isWin = false;
|
|
|
+ GameMgr.inst.setGameStatus(GameStatus.Revive);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -213,7 +237,7 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
/** 追击目标 */
|
|
|
private chaseTarget(target: Node) {
|
|
|
if (this.isChasing) return;
|
|
|
- // console.log(`AI 追击目标-> ${target.name}}`);
|
|
|
+ console.log(`AI 追击目标-> ${target.name}}`);
|
|
|
|
|
|
this.isChasing = true;
|
|
|
this.targetNode = target;
|
|
@@ -252,6 +276,12 @@ export class TornadoAIComponent extends TornadoComponent {
|
|
|
}, this.escapeDuration);
|
|
|
}
|
|
|
|
|
|
+ private stormResurrect() {
|
|
|
+ // console.log(`玩家复活 AI取消行为 重新选择行为!`);
|
|
|
+ this.cancelAction();
|
|
|
+ this.decideAction();
|
|
|
+ }
|
|
|
+
|
|
|
//取消AI行为
|
|
|
private cancelAction() {
|
|
|
this.unscheduleAllCallbacks();
|