Browse Source

敌人移动解决

181404010226 2 months ago
parent
commit
98f7212115

+ 11 - 11
assets/Scenes/GameLevel.scene

@@ -596,10 +596,10 @@
         "__id__": 21
       },
       {
-        "__id__": 260
+        "__id__": 29
       },
       {
-        "__id__": 29
+        "__id__": 260
       },
       {
         "__id__": 11
@@ -1132,13 +1132,13 @@
     },
     "_enabled": true,
     "__prefab": null,
-    "enabledContactListener": false,
+    "enabledContactListener": true,
     "bullet": false,
     "awakeOnLoad": true,
     "_group": 32,
     "_type": 0,
     "_allowSleep": true,
-    "_gravityScale": 0,
+    "_gravityScale": 1,
     "_linearDamping": 0,
     "_angularDamping": 0,
     "_linearVelocity": {
@@ -1168,13 +1168,13 @@
     "_restitution": 1,
     "_offset": {
       "__type__": "cc.Vec2",
-      "x": 0,
-      "y": 0
+      "x": -8.6,
+      "y": -1.7
     },
     "_size": {
       "__type__": "cc.Size",
-      "width": 705,
-      "height": 58
+      "width": 712.5,
+      "height": 54.8
     },
     "_id": "a1erCLzJJJVJN3WWQPYVee"
   },
@@ -2056,7 +2056,7 @@
     },
     "_enabled": true,
     "__prefab": null,
-    "enabledContactListener": false,
+    "enabledContactListener": true,
     "bullet": false,
     "awakeOnLoad": true,
     "_group": 32,
@@ -31230,7 +31230,7 @@
     "_prefab": null,
     "_lpos": {
       "__type__": "cc.Vec3",
-      "x": 11.744140624999998,
+      "x": 11.744140625000002,
       "y": 0,
       "z": 0
     },
@@ -31357,7 +31357,7 @@
     "_right": 0,
     "_top": 4.062999999999998,
     "_bottom": 0.37195384615384625,
-    "_horizontalCenter": 0.06382685122282608,
+    "_horizontalCenter": 0.0638268512228261,
     "_verticalCenter": 0,
     "_isAbsLeft": true,
     "_isAbsRight": true,

+ 3 - 3
assets/assets/Prefabs/Enemy.prefab

@@ -100,7 +100,7 @@
     "_lpos": {
       "__type__": "cc.Vec3",
       "x": 0,
-      "y": 129.5248447204969,
+      "y": 38.84161490683229,
       "z": 0
     },
     "_lrot": {
@@ -868,7 +868,7 @@
     "_lpos": {
       "__type__": "cc.Vec3",
       "x": 0,
-      "y": 16.0248447204969,
+      "y": -74.65838509316771,
       "z": 0
     },
     "_lrot": {
@@ -1063,7 +1063,7 @@
     "_contentSize": {
       "__type__": "cc.Size",
       "width": 77.5,
-      "height": 150
+      "height": 50
     },
     "_anchorPoint": {
       "__type__": "cc.Vec2",

+ 8 - 2
assets/scripts/CombatSystem/EnemyInstance.ts

@@ -636,8 +636,14 @@ export class EnemyInstance extends Component {
         // 移除基于距离的攻击触发逻辑,只通过碰撞回调触发攻击
         // 这样可以确保攻击触发的准确性,避免位置计算误差
         
-        if (distanceToTarget === 0) return;
-        dir.normalize();
+        // 移除距离为0时的停止逻辑,让敌人继续按原方向移动直到碰撞体触发攻击状态
+        // 如果距离为0,保持上一次的移动方向继续移动
+        if (distanceToTarget > 0) {
+            dir.normalize();
+        } else {
+            // 距离为0时,使用上一次保存的移动方向或默认方向
+            dir.set(this.movingDirection, 0, 0);
+        }
 
         // 获取当前速度(考虑狂暴加成)
         const enemyComponent = this.getComponent(EnemyComponent);