ソースを参照

牛羊 角度运动修改

woso_javan 2 ヶ月 前
コミット
19df0283a8

+ 132 - 10
assets/module_storm_sunder/Prefabs/Props/cow.prefab

@@ -25,17 +25,17 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 20
+        "__id__": 28
       },
       {
-        "__id__": 22
+        "__id__": 30
       },
       {
-        "__id__": 24
+        "__id__": 32
       }
     ],
     "_prefab": {
-      "__id__": 26
+      "__id__": 34
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -136,6 +136,24 @@
       },
       {
         "__id__": 19
+      },
+      {
+        "__id__": 20
+      },
+      {
+        "__id__": 22
+      },
+      {
+        "__id__": 23
+      },
+      {
+        "__id__": 25
+      },
+      {
+        "__id__": 26
+      },
+      {
+        "__id__": 27
       }
     ],
     "removedComponents": []
@@ -182,9 +200,9 @@
     "value": {
       "__type__": "cc.Quat",
       "x": 0,
-      "y": 0,
+      "y": -0.7071067811865475,
       "z": 0,
-      "w": 1
+      "w": 0.7071067811865476
     }
   },
   {
@@ -198,7 +216,7 @@
     "value": {
       "__type__": "cc.Vec3",
       "x": 0,
-      "y": 0,
+      "y": -90,
       "z": 0
     }
   },
@@ -317,6 +335,110 @@
       "__expectedType__": "cc.AnimationClip"
     }
   },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 21
+    },
+    "propertyPath": [
+      "_lrot"
+    ],
+    "value": {
+      "__type__": "cc.Quat",
+      "x": 0,
+      "y": 0,
+      "z": 0.7071067811865475,
+      "w": 0.7071067811865476
+    }
+  },
+  {
+    "__type__": "cc.TargetInfo",
+    "localID": [
+      "51iQyD8XlfQbIGGm9qNI4W"
+    ]
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 21
+    },
+    "propertyPath": [
+      "_euler"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 90
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 24
+    },
+    "propertyPath": [
+      "_lpos"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    }
+  },
+  {
+    "__type__": "cc.TargetInfo",
+    "localID": [
+      "14phBEV0tRooz0GxMOYEX0"
+    ]
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 24
+    },
+    "propertyPath": [
+      "_euler"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": -2.36016652067128e-13
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 24
+    },
+    "propertyPath": [
+      "_lrot"
+    ],
+    "value": {
+      "__type__": "cc.Quat",
+      "x": 0,
+      "y": 0,
+      "z": -2.0596338340526325e-15,
+      "w": 1
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 21
+    },
+    "propertyPath": [
+      "_lpos"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 1.3127117171052305e-8
+    }
+  },
   {
     "__type__": "cc.RigidBody",
     "_name": "",
@@ -327,7 +449,7 @@
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 21
+      "__id__": 29
     },
     "_group": 16,
     "_type": 4,
@@ -364,7 +486,7 @@
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 23
+      "__id__": 31
     },
     "_material": null,
     "_isTrigger": false,
@@ -396,7 +518,7 @@
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 25
+      "__id__": 33
     },
     "hp": 1,
     "currentExp": 4,

+ 132 - 10
assets/module_storm_sunder/Prefabs/Props/sheep.prefab

@@ -25,17 +25,17 @@
     "_active": true,
     "_components": [
       {
-        "__id__": 16
+        "__id__": 24
       },
       {
-        "__id__": 18
+        "__id__": 26
       },
       {
-        "__id__": 20
+        "__id__": 28
       }
     ],
     "_prefab": {
-      "__id__": 22
+      "__id__": 30
     },
     "_lpos": {
       "__type__": "cc.Vec3",
@@ -124,6 +124,24 @@
       },
       {
         "__id__": 15
+      },
+      {
+        "__id__": 16
+      },
+      {
+        "__id__": 18
+      },
+      {
+        "__id__": 19
+      },
+      {
+        "__id__": 21
+      },
+      {
+        "__id__": 22
+      },
+      {
+        "__id__": 23
       }
     ],
     "removedComponents": []
@@ -170,9 +188,9 @@
     "value": {
       "__type__": "cc.Quat",
       "x": 0,
-      "y": 0,
+      "y": -0.7071067811865475,
       "z": 0,
-      "w": 1
+      "w": 0.7071067811865476
     }
   },
   {
@@ -186,7 +204,7 @@
     "value": {
       "__type__": "cc.Vec3",
       "x": 0,
-      "y": 0,
+      "y": -90,
       "z": 0
     }
   },
@@ -251,6 +269,110 @@
       "__expectedType__": "cc.Skeleton"
     }
   },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 17
+    },
+    "propertyPath": [
+      "_lrot"
+    ],
+    "value": {
+      "__type__": "cc.Quat",
+      "x": 0,
+      "y": 0,
+      "z": 0.7071067811865475,
+      "w": 0.7071067811865476
+    }
+  },
+  {
+    "__type__": "cc.TargetInfo",
+    "localID": [
+      "cdVkQXazJT07HzJFpQfHkR"
+    ]
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 17
+    },
+    "propertyPath": [
+      "_euler"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 90
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 20
+    },
+    "propertyPath": [
+      "_euler"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": -2.36016652067128e-13
+    }
+  },
+  {
+    "__type__": "cc.TargetInfo",
+    "localID": [
+      "09G0/7yqhW9bgPwwdZEpE3"
+    ]
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 20
+    },
+    "propertyPath": [
+      "_lrot"
+    ],
+    "value": {
+      "__type__": "cc.Quat",
+      "x": 0,
+      "y": 0,
+      "z": -2.0596338340526325e-15,
+      "w": 1
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 20
+    },
+    "propertyPath": [
+      "_lpos"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 0
+    }
+  },
+  {
+    "__type__": "CCPropertyOverrideInfo",
+    "targetInfo": {
+      "__id__": 17
+    },
+    "propertyPath": [
+      "_lpos"
+    ],
+    "value": {
+      "__type__": "cc.Vec3",
+      "x": 0,
+      "y": 0,
+      "z": 1.3127117171052305e-8
+    }
+  },
   {
     "__type__": "cc.RigidBody",
     "_name": "",
@@ -261,7 +383,7 @@
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 17
+      "__id__": 25
     },
     "_group": 16,
     "_type": 4,
@@ -298,7 +420,7 @@
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 19
+      "__id__": 27
     },
     "_material": null,
     "_isTrigger": false,
@@ -330,7 +452,7 @@
     },
     "_enabled": true,
     "__prefab": {
-      "__id__": 21
+      "__id__": 29
     },
     "hp": 1,
     "currentExp": 2,

+ 26 - 27
assets/module_storm_sunder/Script/Component/PropMoveComponent.ts

@@ -13,6 +13,8 @@ export class PropMoveComponent extends PropComponent {
     @property({ type: CCFloat, displayName: "移动速度" })
     moveSpeed: number = 10;
 
+    _moveDir: Vec3 = new Vec3();
+
     // 当前移动方向
     private currentDirection: Vec3 = new Vec3();
     // 已移动距离
@@ -23,15 +25,9 @@ export class PropMoveComponent extends PropComponent {
 
         this.moveSpeed = Math.round((this.moveSpeed / 10) * 100) / 100;
         // 初始化随机移动方向
-        // this.randomAngle();
         this.changeDirection();
     }
 
-    //随机角度
-    private randomAngle() {
-        this.node.setRotationFromEuler(0, randomRange(0, 360), 0);
-    }
-
     protected override onTriggerEnter(event: ITriggerEvent) {
         // super.onTriggerEnter(event);
 
@@ -42,19 +38,31 @@ export class PropMoveComponent extends PropComponent {
 
     //反方向运动 
     private oppositeDirection() {
-        // 获取当前角度并加180度实现反向
-        const currentAngle = this.node.eulerAngles.y;
-        this.node.setRotationFromEuler(0, currentAngle + 180, 0);
+        // 直接反转当前的移动方向
+        this._moveDir.negative();
+
+        // 更新朝向
+        const targetPos = this.node.worldPosition.clone().add(this._moveDir);
+        this.node.lookAt(targetPos);
+
+        // 重置已移动距离
+        this.distanceMoved = 0;
     }
 
     /**
      * 改变移动方向
      */
     private changeDirection() {
-        // 随机一个新的旋转角度
-        const newAngle = randomRange(0, 360);
-        // 设置节点的旋转
-        this.node.setRotationFromEuler(0, newAngle, 0);
+        // 随机生成一个方向(限制在XZ平面上)
+        const angle = randomRange(0, 360);
+        const rad = angle * Math.PI / 180;
+
+        this._moveDir.set(Math.sin(rad), 0, Math.cos(rad));
+        this._moveDir.normalize();
+
+        // 更新朝向
+        const targetPos = this.node.worldPosition.clone().add(this._moveDir);
+        this.node.lookAt(targetPos);
         // 重置已移动距离
         this.distanceMoved = 0;
     }
@@ -62,26 +70,17 @@ export class PropMoveComponent extends PropComponent {
     update(deltaTime: number) {
         if (this.status === PropStatus.DIE) return;
 
-        // 计算当前帧移动距离
-        const moveStep = this.moveSpeed * deltaTime;
-
-        // 更新已移动距离
-        this.distanceMoved += moveStep;
-
         // 获取物体的前向方向
         const forward = new Vec3();
         Vec3.transformQuat(forward, Vec3.FORWARD, this.node.getWorldRotation());
         forward.normalize();
 
         // 计算移动向量
-        const moveVec = new Vec3(
-            -forward.x * moveStep,
-            0,
-            forward.z * moveStep
-        );
-
-        // 更新位置
-        this.node.position = this.node.position.add(moveVec);
+        const moveStep = forward.multiplyScalar(this.moveSpeed * deltaTime);
+        this.node.worldPosition = this.node.worldPosition.add(moveStep);
+
+        // 更新已移动距离
+        this.distanceMoved += moveStep.length();
 
         // 如果已移动距离超过设定值,改变方向
         if (this.distanceMoved >= this.moveDistance) {

+ 0 - 4
assets/module_storm_sunder/Script/Manager/PropMgr.ts

@@ -6,10 +6,6 @@ import { PlayerMgr } from "./PlayerMgr";
 import { GameMgr, GameStatus } from "./GameMgr";
 
 const propRes = [
-    // "Prefabs/Props/altman",
-    // "Prefabs/Props/aula",
-    // "Prefabs/Props/clown",
-    // "Prefabs/Props/hellFire",
     "Prefabs/Props/cow",
     "Prefabs/Props/sheep",
 ]

+ 2 - 2
settings/v2/packages/information.json

@@ -7,7 +7,7 @@
       "enable": true,
       "customSplash": {
         "complete": true,
-        "form": "https://creator-api.cocos.com/api/form/show?sid=1b5d5bf985437b6f957cb414ac09793a"
+        "form": "https://creator-api.cocos.com/api/form/show?sid=441f33883f4cc43ae3cef841ef990d52"
       }
     },
     "removeSplash": {
@@ -16,7 +16,7 @@
       "enable": true,
       "removeSplash": {
         "complete": true,
-        "form": "https://creator-api.cocos.com/api/form/show?sid=1b5d5bf985437b6f957cb414ac09793a"
+        "form": "https://creator-api.cocos.com/api/form/show?sid=441f33883f4cc43ae3cef841ef990d52"
       }
     }
   }