Explorar o código

移动道具 随机移动

woso_javan hai 2 meses
pai
achega
0909faedc2

+ 1 - 0
assets/module_storm_sunder/Prefabs/Buildings/farm_plot.prefab

@@ -403,6 +403,7 @@
     },
     "hp": 50,
     "exp": 10,
+    "isMove": false,
     "_id": ""
   },
   {

+ 325 - 0
assets/module_storm_sunder/Prefabs/Props/altman01.prefab

@@ -0,0 +1,325 @@
+[
+  {
+    "__type__": "cc.Prefab",
+    "_name": "altman01",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "_native": "",
+    "data": {
+      "__id__": 1
+    },
+    "optimizationPolicy": 0,
+    "persistent": false
+  },
+  {
+    "__type__": "cc.Node",
+    "_name": "altman01",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "_parent": null,
+    "_children": [
+      {
+        "__id__": 2
+      }
+    ],
+    "_active": true,
+    "_components": [
+      {
+        "__id__": 13
+      },
+      {
+        "__id__": 15
+      },
+      {
+        "__id__": 17
+      }
+    ],
+    "_prefab": {
+      "__id__": 19
+    },
+    "_lpos": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    },
+    "_lrot": {
+      "__type__": "cc.Quat",
+      "x": 0,
+      "y": 0,
+      "z": 0,
+      "w": 1
+    },
+    "_lscale": {
+      "__type__": "cc.Vec3",
+      "x": 3,
+      "y": 3,
+      "z": 3
+    },
+    "_mobility": 0,
+    "_layer": 1073741824,
+    "_euler": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    },
+    "_id": ""
+  },
+  {
+    "__type__": "cc.Node",
+    "_objFlags": 0,
+    "_parent": {
+      "__id__": 1
+    },
+    "_prefab": {
+      "__id__": 3
+    },
+    "__editorExtras__": {}
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 2
+    },
+    "asset": {
+      "__uuid__": "5f35effe-a1a1-4c6a-8a36-5ad85ff66628@cba0f",
+      "__expectedType__": "cc.Prefab"
+    },
+    "fileId": "2e/YmFhY1TZqm7EAN5fwZk",
+    "instance": {
+      "__id__": 4
+    },
+    "targetOverrides": null
+  },
+  {
+    "__type__": "cc.PrefabInstance",
+    "fileId": "85PhQfU6NOS62hDJ2XVorm",
+    "prefabRootNode": {
+      "__id__": 1
+    },
+    "mountedChildren": [],
+    "mountedComponents": [],
+    "propertyOverrides": [
+      {
+        "__id__": 5
+      },
+      {
+        "__id__": 7
+      },
+      {
+        "__id__": 8
+      },
+      {
+        "__id__": 9
+      },
+      {
+        "__id__": 10
+      },
+      {
+        "__id__": 11
+      }
+    ],
+    "removedComponents": []
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 6
+    },
+    "propertyPath": [
+      "_name"
+    ],
+    "value": "altman01"
+  },
+  {
+    "__type__": "cc.TargetInfo",
+    "localID": [
+      "2e/YmFhY1TZqm7EAN5fwZk"
+    ]
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 6
+    },
+    "propertyPath": [
+      "_lpos"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 6
+    },
+    "propertyPath": [
+      "_lrot"
+    ],
+    "value": {
+      "__type__": "cc.Quat",
+      "x": 0,
+      "y": 0,
+      "z": 0,
+      "w": 1
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 6
+    },
+    "propertyPath": [
+      "_euler"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 6
+    },
+    "propertyPath": [
+      "_lscale"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 1,
+      "y": 1,
+      "z": 1
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 12
+    },
+    "propertyPath": [
+      "playOnLoad"
+    ],
+    "value": true
+  },
+  {
+    "__type__": "cc.TargetInfo",
+    "localID": [
+      "3d3CdV10leJoXmj+qSsugX"
+    ]
+  },
+  {
+    "__type__": "cc.RigidBody",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 1
+    },
+    "_enabled": true,
+    "__prefab": {
+      "__id__": 14
+    },
+    "_group": 16,
+    "_type": 4,
+    "_mass": 1,
+    "_allowSleep": true,
+    "_linearDamping": 0.1,
+    "_angularDamping": 0.1,
+    "_useGravity": true,
+    "_linearFactor": {
+      "__type__": "cc.Vec3",
+      "x": 1,
+      "y": 1,
+      "z": 1
+    },
+    "_angularFactor": {
+      "__type__": "cc.Vec3",
+      "x": 1,
+      "y": 1,
+      "z": 1
+    },
+    "_id": ""
+  },
+  {
+    "__type__": "cc.CompPrefabInfo",
+    "fileId": "59JJzdl3dEwrl+JuoTc/gp"
+  },
+  {
+    "__type__": "cc.BoxCollider",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 1
+    },
+    "_enabled": true,
+    "__prefab": {
+      "__id__": 16
+    },
+    "_material": null,
+    "_isTrigger": true,
+    "_center": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 1,
+      "z": 0
+    },
+    "_size": {
+      "__type__": "cc.Vec3",
+      "x": 1.6,
+      "y": 2.2,
+      "z": 1
+    },
+    "_id": ""
+  },
+  {
+    "__type__": "cc.CompPrefabInfo",
+    "fileId": "0e16BLNNtB2YddqQud8twv"
+  },
+  {
+    "__type__": "9765f4UAXVMHqaZF3DacQSU",
+    "_name": "",
+    "_objFlags": 0,
+    "__editorExtras__": {},
+    "node": {
+      "__id__": 1
+    },
+    "_enabled": true,
+    "__prefab": {
+      "__id__": 18
+    },
+    "hp": 10,
+    "exp": 20,
+    "isMove": true,
+    "_id": ""
+  },
+  {
+    "__type__": "cc.CompPrefabInfo",
+    "fileId": "3aHwGvhYRNzbPQ/z7bT2zB"
+  },
+  {
+    "__type__": "cc.PrefabInfo",
+    "root": {
+      "__id__": 1
+    },
+    "asset": {
+      "__id__": 0
+    },
+    "fileId": "c46/YsCPVOJYA4mWEpNYRx",
+    "instance": null,
+    "targetOverrides": null,
+    "nestedPrefabInstanceRoots": [
+      {
+        "__id__": 2
+      }
+    ]
+  }
+]

+ 13 - 0
assets/module_storm_sunder/Prefabs/Props/altman01.prefab.meta

@@ -0,0 +1,13 @@
+{
+  "ver": "1.1.50",
+  "importer": "prefab",
+  "imported": true,
+  "uuid": "209d0d55-092f-479c-bb84-0eb635412d45",
+  "files": [
+    ".json"
+  ],
+  "subMetas": {},
+  "userData": {
+    "syncNodeName": "altman01"
+  }
+}

+ 9 - 1
assets/module_storm_sunder/Script/Component/PropComponent.ts

@@ -1,4 +1,4 @@
-import { _decorator, CCFloat, Collider, Component, ITriggerEvent, Node, tween, Tween, Vec3 } from 'cc';
+import { _decorator, CCBoolean, CCFloat, Collider, Component, ITriggerEvent, Node, tween, Tween, Vec3 } from 'cc';
 import { Effect2DUIMgr } from '../Manager/Effect2DUIMgr';
 const { ccclass, property } = _decorator;
 
@@ -16,6 +16,9 @@ export class PropComponent extends Component {
     @property({ type: CCFloat })
     exp: number = 10;
 
+    @property({ type: CCBoolean, displayName: "是否可移动" })
+    isMove: boolean = false;
+
     currentHp: number = 0;
     status: PropStatus = PropStatus.LIFE;
     speed: number = 50;
@@ -27,6 +30,7 @@ export class PropComponent extends Component {
         this.currentHp = this.hp;
 
         this.tigger = this.node.getComponent(Collider)!;
+        this.tigger.on('onTriggerEnter', this.onTriggerEnter, this);
         this.tigger.on('onTriggerExit', this.onTriggerExit, this);
     }
 
@@ -63,6 +67,10 @@ export class PropComponent extends Component {
             .start();
     }
 
+    protected onTriggerEnter(event: ITriggerEvent): void {
+        console.log(`道具发生碰撞 onTriggerEnter1111111111111111`);
+    }
+
     onTriggerExit(event: ITriggerEvent): void {
         Effect2DUIMgr.Instance.removeBlood(this.node);
     }

+ 85 - 0
assets/module_storm_sunder/Script/Component/PropMoveComponent.ts

@@ -0,0 +1,85 @@
+import { _decorator, Component, Collider, ITriggerEvent, Node, CCFloat, Vec3, randomRange } from 'cc';
+import { PropComponent, PropStatus } from './PropComponent';
+const { ccclass, property } = _decorator;
+
+@ccclass('PropMoveComponent')
+export class PropMoveComponent extends PropComponent {
+
+    @property({ type: CCFloat, displayName: "移动距离" })
+    moveDistance: number = 10;
+
+    @property({ type: CCFloat, displayName: "移动速度" })
+    moveSpeed: number = 10;
+
+    // 当前移动方向
+    private currentDirection: Vec3 = new Vec3();
+    // 已移动距离
+    private distanceMoved: number = 0;
+    // 是否正在移动
+    private isMoving: boolean = false;
+
+    start() {
+        super.start();
+
+        // 初始化随机移动方向
+        this.changeDirection();
+    }
+
+    protected override onTriggerEnter(event: ITriggerEvent) {
+        // super.onTriggerEnter(event);
+
+        const otherCollider = event.otherCollider;
+        const otherNode = otherCollider.node;
+
+        console.log(`移动道具碰撞信息:${event.otherCollider.node.name}`);
+
+        // 碰撞后改变方向
+        this.changeDirection();
+    }
+
+    /**
+     * 改变移动方向
+     */
+    private changeDirection() {
+        // 随机生成一个水平方向(x和z轴)
+        const randomX = randomRange(-1, 1);
+        const randomZ = randomRange(-1, 1);
+
+        // 设置新的移动方向并归一化
+        this.currentDirection.set(randomX, 0, randomZ);
+        this.currentDirection.normalize();
+
+        // 重置已移动距离
+        this.distanceMoved = 0;
+        this.isMoving = true;
+
+        console.log(`改变移动方向: (${this.currentDirection.x}, ${this.currentDirection.z})`);
+    }
+
+    update(deltaTime: number) {
+        if (!this.isMoving || this.status === PropStatus.DIE) return;
+
+        // 计算当前帧移动距离
+        const moveStep = this.moveSpeed * deltaTime;
+
+        // 更新已移动距离
+        this.distanceMoved += moveStep;
+
+        // 计算移动向量
+        const moveVec = new Vec3(
+            this.currentDirection.x * moveStep,
+            0,
+            this.currentDirection.z * moveStep
+        );
+
+        // 更新位置
+        this.node.position = this.node.position.add(moveVec);
+
+        // 如果已移动距离超过设定值,改变方向
+        if (this.distanceMoved >= this.moveDistance) {
+            this.changeDirection();
+        }
+    }
+}
+
+

+ 9 - 0
assets/module_storm_sunder/Script/Component/PropMoveComponent.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "9765fe14-0175-4c1e-a699-1770da710494",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 254 - 127
assets/module_storm_sunder/rooster_stormsunder.scene


Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio