woso_javan пре 2 месеци
родитељ
комит
9f9309b72d

+ 12 - 9
assets/module_storm_sunder/Script/Component/TornadoAIComponent.ts

@@ -1,4 +1,4 @@
-import { BoxCollider, Component, ITriggerEvent, Node, Vec3, _decorator, randomRange } from 'cc';
+import { BoxCollider, Component, ITriggerEvent, Node, Tween, Vec3, _decorator, randomRange } from 'cc';
 import { PathfindingManager } from '../Manager/PathfindingManager';
 import { PlayerStatus, TornadoComponent } from './TornadoComponent';
 import { PropStatus } from './PropComponent';
@@ -48,8 +48,7 @@ export class TornadoAIComponent extends TornadoComponent {
         //text:名称 range:检测半径 move_juge:移动概率 move_time:移动时间 escape_time:逃跑时间 pursuit_1:追击玩家概率 pursuit_2:追击AI概率 pursuit_time:追击时间
         const { text, range, move_judge, move_time, escape_time, pursuit_1, pursuit_2, pursuit_time } = aiConfig.data;
         this.playerInfo.nickName = text;
-        this.playerInfo.level = 2;
-        this.currentLv = this.playerInfo.level;
+        this.playerInfo.level = this.currentLv;
 
         this.moveDuration = Math.floor(move_time[0] + Math.random() * (move_time[1] - move_time[0] + 1));
         this.escapeDuration = Math.floor(escape_time[0] + Math.random() * (escape_time[1] - escape_time[0] + 1));
@@ -62,7 +61,7 @@ export class TornadoAIComponent extends TornadoComponent {
         this.attack = this.attributeBonusMgr.getStormSunderAttack(this.currentLv, true);
         this.speed = this.attributeBonusMgr.getStormSunderSpeed(this.currentLv, true);
 
-        console.log(`AI 攻击力:${this.attack} 速度:${this.speed} 下一级经验:${this.nextExp}`)
+        // console.log(`AI 攻击力:${this.attack} 速度:${this.speed} 下一级经验:${this.nextExp}`);
     }
 
     /** 选择 AI 行为 */
@@ -101,7 +100,7 @@ export class TornadoAIComponent extends TornadoComponent {
         const targetPosition = this.node.position.clone().add(randomDirection);
 
         PathfindingManager.getInstance().moveTo(this.node, targetPosition, this.moveDuration);
-        console.log(`AI 触发随机移动行为!`, targetPosition);
+        // console.log(`AI 触发随机移动行为!`, targetPosition);
 
         this.scheduleOnce(() => {
             if (!this.isChasing && !this.isEscaping) { // 再次检查状态,避免重复调用
@@ -111,13 +110,16 @@ export class TornadoAIComponent extends TornadoComponent {
     }
 
     protected onTriggerEnter(event: ITriggerEvent): void {
-        // super.onTriggerEnter(event);
         if (event.otherCollider.getGroup() === 1 << 2) {
             this.unscheduleAllCallbacks();
             this.isChasing = false;
             this.isEscaping = false;
             this.targetNode = null;
-            this.decideAction();
+            Tween.stopAllByTarget(this.node);
+
+            this.setPositionByObstacle(event, () => {
+                this.decideAction();
+            });
         }
     }
 
@@ -138,7 +140,7 @@ export class TornadoAIComponent extends TornadoComponent {
 
     protected addExpByKill() {
         super.addExpByKill(true);
-        console.log(`AI 当前经验:${this.currentExp}`);
+        // console.log(`AI 当前经验:${this.currentExp}`);
     }
 
     /** 触发器检测(过程中遇到其他龙卷风) */
@@ -220,7 +222,8 @@ export class TornadoAIComponent extends TornadoComponent {
         const maxDistance = this.speed * this.escapeDuration;
 
         // 计算逃离方向,指向目标的反方向
-        const direction = this.node.position.clone().subtract(target.position).normalize().multiplyScalar(maxDistance);
+        const targetPos = new Vec3(target.position.x, 0, target.position.z);
+        const direction = this.node.position.clone().subtract(targetPos).normalize().multiplyScalar(maxDistance);
         const escapePosition = this.node.position.clone().add(direction);
 
         PathfindingManager.getInstance().moveTo(this.node, escapePosition, this.escapeDuration);

+ 22 - 15
assets/module_storm_sunder/Script/Component/TornadoComponent.ts

@@ -93,27 +93,34 @@ export class TornadoComponent extends Component {
     protected onTriggerEnter(event: ITriggerEvent): void {
         if (GameMgr.inst.gameStatus !== GameStatus.Playing) return;
 
-        let _originalPosition = this.node.position.clone();
         if (event.otherCollider.getGroup() === 1 << 2) {
-            if (this.isColliding) return; // 防止重复触发
+            this.setPositionByObstacle(event);
+        }
+    }
 
-            this.isColliding = true;
-            _originalPosition = this.node.position.clone(); // 记录碰撞前坐标
+    protected setPositionByObstacle(event: ITriggerEvent, cb?: Function) {
+        console.log('离开碰撞物 isColliding:', this.isColliding);
+        if (this.isColliding) return; // 防止重复触发
 
-            // 计算反方向移动(保持Y轴不变)
-            const reverseDirection = this.calculateReverseDirection(event);
-            const newPosition = _originalPosition.add(reverseDirection);
+        let _originalPosition = this.node.position.clone();
+        this.isColliding = true;
+        _originalPosition = this.node.position.clone(); // 记录碰撞前坐标
 
-            // 直接修改坐标
-            this.node.setPosition(newPosition);
-            setTimeout(() => {
-                this.isColliding = false;
-            }, 500);
-        }
+        // 计算反方向移动(保持Y轴不变)
+        const reverseDirection = this.calculateReverseDirection(event);
+        const newPosition = _originalPosition.add(reverseDirection);
+
+        // 直接修改坐标
+        this.node.setPosition(newPosition);
+
+        setTimeout(() => {
+            this.isColliding = false;
+            if (cb) cb();
+        }, 500);
     }
 
     // 计算反方向(基于障碍物位置)
-    private calculateReverseDirection(event: ITriggerEvent): Vec3 {
+    protected calculateReverseDirection(event: ITriggerEvent): Vec3 {
         // 获取障碍物节点位置
         const obstaclePos = event.otherCollider.node.worldPosition;
         const selfPos = this.node.worldPosition;
@@ -126,7 +133,7 @@ export class TornadoComponent extends Component {
         );
 
         // 归一化并乘以反冲距离
-        return direction.normalize().multiplyScalar(5);
+        return direction.normalize().multiplyScalar(7);
     }
 
     protected onTriggerStay(event: ITriggerEvent): void {

+ 1 - 1
assets/module_storm_sunder/Script/Manager/PathfindingManager.ts

@@ -32,7 +32,7 @@ export class PathfindingManager {
                 return;
             }
 
-            console.log('追击中...')
+            // console.log('追击中...');
             const aiNode = aiComponent.node;
             const targetPos = targetNode.worldPosition;
             const myPos = aiNode.worldPosition;

+ 1 - 1
assets/module_storm_sunder/Script/Manager/PlayerMgr.ts

@@ -26,7 +26,7 @@ export class PlayerMgr {
 
     public tornadoNode: Node = null;//玩家节点
     public aiPlayersConfig: Map<number, any> = new Map();//AI玩家配置
-    public createAIPlayerCount: number = 1;//创建AI玩家数量
+    public createAIPlayerCount: number = 3;//创建AI玩家数量
     public aiConfigCount: number = 3;//AI配置数量
 
     private aiIndex: number = 0;//AI索引

+ 22 - 1
assets/module_storm_sunder/Script/Manager/PropMgr.ts

@@ -102,9 +102,30 @@ export class PropMgr {
         if (!this.tornadoNode || !this.tornadoNode.worldPosition) return;
 
         let playerPos = this.tornadoNode.worldPosition;
-
         let angle = Math.random() * Math.PI * 2; // 随机角度
         let distance = Math.random() * this.spawnRadius + this.spawnRadius;
+
+        // 创建射线检测前方障碍物
+        let ray = new geometry.Ray(
+            playerPos.x,
+            playerPos.y,
+            playerPos.z,
+            Math.cos(angle),
+            0,
+            Math.sin(angle)
+        );
+
+        let hit = PhysicsSystem.instance.raycastClosest(ray, distance, 1 << 2);
+
+        if (hit) {
+            // 如果检测到障碍物,将生成距离调整为龙卷风到障碍物之间
+            let hitResult = PhysicsSystem.instance.raycastClosestResult;
+            if (hitResult && hitResult.distance < distance) {
+                // 在龙卷风和障碍物之间随机选择一个位置,留出一定安全距离
+                distance = Math.random() * (hitResult.distance - 1) + 1;
+            }
+        }
+
         let x = playerPos.x + Math.cos(angle) * distance;
         let z = playerPos.z + Math.sin(angle) * distance;
         let y = 0;

Разлика између датотеке није приказан због своје велике величине
+ 259 - 127
assets/module_storm_sunder/rooster_stormsunder.scene


Неке датотеке нису приказане због велике количине промена