Explorar o código

移动道具 碰撞 反向运动

woso_javan hai 2 meses
pai
achega
6ca7f92d29

+ 5 - 4
assets/module_storm_sunder/Script/Component/PropMoveComponent.ts

@@ -30,11 +30,12 @@ export class PropMoveComponent extends PropComponent {
 
         const otherCollider = event.otherCollider;
         const otherNode = otherCollider.node;
+        this.oppositeDirection();
+    }
 
-        console.log(`移动道具碰撞信息:${event.otherCollider.node.name}`);
-
-        // 碰撞后改变方向
-        this.changeDirection();
+    //反方向运动 
+    private oppositeDirection() {
+        this.currentDirection.multiplyScalar(-1);
     }
 
     /**

+ 16 - 8
assets/module_storm_sunder/Script/Manager/PropMgr.ts

@@ -28,7 +28,7 @@ export class PropMgr {
     //数量上限
     public propMaxNum: number = 100;
     //生成周期
-    public propCreateCycle: number = 1;
+    public propCreateCycle: number = 3;
     //生成数量
     public propCreateNum: number = 10;
 
@@ -37,6 +37,7 @@ export class PropMgr {
     public spawnRadius: number = 20; // 生成范围半径
     public raycastDistance: number = 1;//射线检测距离
     currentPropsCount: number = 0; //当前道具数量
+    lastCreateTime: number = 0;//上次生成时间
 
     public genaratorInitialData() {
         //DOTO 取配置 先定义假数据
@@ -47,9 +48,17 @@ export class PropMgr {
         this.propCreateNum = 1;
     }
 
-    public update(deltaTime?: number) {
-        //DOTO 生成道具
-        // console.log('deltaTime:', deltaTime);
+    public update(deltaTime: number) {
+        if (this.currentPropsCount >= this.propMaxNum) return;
+
+        const currentTime = game.totalTime / 1000; // 转换为秒
+
+        // 检查是否达到生成周期
+        if (currentTime - this.lastCreateTime >= this.propCreateCycle) {
+            this.lastCreateTime = currentTime; // 更新上次生成时间
+            this.genatorProp(); // 执行生成道具逻辑
+            console.log(`道具生成周期到达,当前道具数量:${this.currentPropsCount}`);
+        }
     }
 
     public async genatorProp() {
@@ -60,7 +69,6 @@ export class PropMgr {
 
         for (let index = 0; index < this.propInitNum; index++) {
             let spawnPos = this.getValidSpawnPosition();
-            console.log(`随机点:${spawnPos.x},${spawnPos.y}}`)
             // 进行四向物理检测
             if (!this.isPositionBlocked(spawnPos)) {
                 const propPrefab = await resLoader.loadAsync(resLoader.gameBundleName, propRes[Math.floor(Math.random() * propRes.length)]);
@@ -68,10 +76,10 @@ export class PropMgr {
                 newMonster.setParent(propsUI);
                 newMonster.setWorldPosition(spawnPos);
                 this.currentPropsCount++;
-                console.log("怪物生成成功", spawnPos);
+                // console.log("怪物生成成功", spawnPos);
             }
 
-            console.warn("未找到合适的怪物生成点");
+            // console.warn("未找到合适的怪物生成点");
         }
     }
 
@@ -106,7 +114,7 @@ export class PropMgr {
         if (PhysicsSystem.instance.raycastClosest(ray, this.raycastDistance)) {
             let hit = PhysicsSystem.instance.raycastClosestResult;
             if (hit && hit.collider) {
-                console.log("检测到障碍物", hit.collider.node.name, "位置", position);
+                // console.log("检测到障碍物", hit.collider.node.name, "位置", position);
                 return true; // 当前位置有障碍物
             }
         }