woso_javan 1 месяц назад
Родитель
Сommit
29098d6825

+ 9 - 1
assets/module_aliens/Script/Components/RadarComponent.ts

@@ -13,6 +13,8 @@ export class RadarComponent extends Component {
 
     private _shouldUpdatePosition = true;
 
+    private _index = 0;
+
     protected onLoad(): void {
         this.registerEvent();
     }
@@ -84,7 +86,13 @@ export class RadarComponent extends Component {
         return new Promise<Node>((resolve, reject) => {
             const levelNode = AliensGlobalInstance.instance.levels.children[0];
             const et = levelNode.getChildByName('et');
-            resolve(et.children[Math.floor(Math.random() * et.children.length)]);
+
+            this._index++;
+            if(this._index >= et.children.length){
+                this._index = 0;
+            }
+            
+            resolve(et.children[this._index]);
             // resolve(et.children[1]);
         });
     }

+ 9 - 1
assets/module_aliens/Script/Components/ScreenShotComponent.ts

@@ -18,6 +18,8 @@ export class ScreenShotComponent extends Component {
     private _originalCameraPosition: Vec3 = new Vec3();
     private _originalCameraRotation: Vec3 = new Vec3();
 
+    private _index:number = 0;
+
     //渲染的目标节点
     private _targetNode: Node = null!;
 
@@ -120,7 +122,13 @@ export class ScreenShotComponent extends Component {
         return new Promise<Node>((resolve, reject) => {
             const levelNode = AliensGlobalInstance.instance.levels.children[0];
             const et = levelNode.getChildByName('et');
-            resolve(et.children[Math.floor(Math.random() * et.children.length)]);
+
+            this._index++;
+            if(this._index >= et.children.length){
+                this._index = 0;
+            }
+            
+            resolve(et.children[this._index]);
         });
     }
 

+ 42 - 68
assets/module_aliens/Script/LevelAction.ts

@@ -42,8 +42,7 @@ export class LevelAction extends Component {
 
     //镜头拉近属性
     private _zoomDuration: number = 0.5; // 拉近持续时间(秒)
-
-    private _raycastType: ERaycastType = ERaycastType.ALL;
+    private isTweening: boolean = false;
 
     onLoad(): void {
         this._cameraOriginalPos = this.camera.node.position.clone();
@@ -165,73 +164,48 @@ export class LevelAction extends Component {
         const camera = this.camera;
         if (!targetNode || !camera) return;
 
-        const targetWorldPos = targetNode.worldPosition.clone();
-        const screenPos = camera.worldToScreen(targetWorldPos, new Vec3());
-
-        const screenSize = view.getVisibleSize();
-        const isInView = screenPos.z > 0 &&
-                         screenPos.x >= 0 && screenPos.x <= screenSize.x &&
-                         screenPos.y >= 0 && screenPos.y <= screenSize.y;
-
-        if (isInView) {
-            this.preciselyLookAt(targetNode);
-        } else {
-            // this.coarselyTurnToTarget(targetNode);
-        }
-        await this.saveCameraState();
-    }
+        const targetPos = new Vec3();
+        targetNode.getWorldPosition(targetPos);
+
+         // 获取相机位置
+         const cameraPos = new Vec3();
+         camera.node.getWorldPosition(cameraPos);
+ 
+         // 计算从相机到目标的方向向量
+         const direction = new Vec3();
+         Vec3.subtract(direction, targetPos, cameraPos);
+         direction.normalize();
+ 
+         // 计算目标欧拉角
+         const targetYaw = math.toDegree(Math.atan2(-direction.x, -direction.z));
+         const targetPitch = math.toDegree(Math.asin(direction.y));
+ 
+         // 获取当前欧拉角
+         const currentRotation = camera.node.eulerAngles.clone();
+ 
+         // 创建一个对象用于tween
+         const tweenObj = {
+             pitch: currentRotation.x,
+             yaw: currentRotation.y
+         };
+ 
+         this.isTweening = true;
+         tween(tweenObj)
+             .to(0.5, {
+                 pitch: targetPitch,
+                 yaw: targetYaw
+             }, {
+                 easing: 'smooth',
+                 onUpdate: () => {
+                     // 更新相机旋转
+                     camera.node.setRotationFromEuler(tweenObj.pitch, tweenObj.yaw, 0);
+                 },
+                 onComplete: () => {
+                     this.isTweening = false;
+                 }
+             })
+             .start();
 
-    //粗略旋转,控制相机大致朝向目标
-    private coarselyTurnToTarget(targetNode: Node) {
-        const camera = this.camera.node;
-        const targetPos = targetNode.worldPosition.clone();
-        
-        // 计算目标方向向量
-        const direction = new Vec3();
-        Vec3.subtract(direction, targetPos, camera.worldPosition);
-        direction.normalize();
-        
-        // 计算粗略旋转角度
-        const roughRotation = new Vec3();
-        roughRotation.y = Math.atan2(direction.x, direction.z) * 180 / Math.PI;
-        roughRotation.x = -Math.asin(direction.y) * 180 / Math.PI;
-        roughRotation.z = 0; // 保持Z轴不变
-        
-        // 使用缓动动画旋转相机
-        tween(camera.eulerAngles)
-            .to(0.3, roughRotation, {
-                easing: 'sineOut',
-                onUpdate: (target: Vec3) => {
-                    camera.setRotationFromEuler(target);
-                }
-            })
-            .start();
-    }
-    
-    //精准对准
-    private preciselyLookAt(targetNode: Node) {
-        const camera = this.camera.node;
-        const targetPos = targetNode.worldPosition.clone();
-        
-        // 保存初始旋转状态
-        const initialRotation = this._originalRotation.clone();
-        
-        // 计算目标相对于相机的方向
-        const direction = new Vec3();
-        Vec3.subtract(direction, targetPos, camera.worldPosition);
-        direction.normalize();
-        
-        // 基于初始旋转状态计算新角度
-        const newRotation = new Vec3();
-        newRotation.y = initialRotation.y - direction.x * 10; // 调整系数
-        newRotation.x = initialRotation.x + direction.y * 10;
-        
-        // 应用旋转限制
-        newRotation.x = Math.max(this.minXRotation, Math.min(this.maxXRotation, newRotation.x));
-        newRotation.y = Math.max(this.minYRotation, Math.min(this.maxYRotation, newRotation.y));
-        
-        // 设置相机旋转
-        camera.setRotationFromEuler(newRotation);
     }
 
     private adjustRotationLimits() {

+ 31 - 31
profiles/v2/packages/scene.json

@@ -1112,31 +1112,6 @@
       },
       "scale": 1
     },
-    "773de0b0-468b-4fbb-965c-36c47d7a4c94": {
-      "position": {
-        "x": 420.35793298021883,
-        "y": 819.0169323799558,
-        "z": 49.48293325437083
-      },
-      "rotation": {
-        "x": -0.11783285597388655,
-        "y": 0.27097356918521603,
-        "z": 0.03342983526203466,
-        "w": 0.9547623730386611
-      },
-      "viewCenter": {
-        "x": 389.3282446228908,
-        "y": 804.2117866248782,
-        "z": -0.7792235762579907
-      },
-      "contentRect": {
-        "x": -720.1034267218894,
-        "y": 138.11781299334973,
-        "width": 0,
-        "height": 0
-      },
-      "scale": 0.14234857934458647
-    },
     "d6678b55-2635-45df-bdce-51e04632740e": {
       "position": {
         "x": 423.70953733934505,
@@ -1262,10 +1237,35 @@
       },
       "scale": 0.9722222222222222
     },
+    "773de0b0-468b-4fbb-965c-36c47d7a4c94": {
+      "position": {
+        "x": 417.9744625726073,
+        "y": 817.8797109428199,
+        "z": 45.62216733081477
+      },
+      "rotation": {
+        "x": -0.11783285597388655,
+        "y": 0.27097356918521603,
+        "z": 0.03342983526203466,
+        "w": 0.9547623730386611
+      },
+      "viewCenter": {
+        "x": 389.3282446228908,
+        "y": 804.2117866248782,
+        "z": -0.7792235762579907
+      },
+      "contentRect": {
+        "x": -787.3778304588586,
+        "y": 191.98608555085048,
+        "width": 0,
+        "height": 0
+      },
+      "scale": 0.125
+    },
     "be14c61f-22d8-4bb9-b444-ad9f29740469": {
       "position": {
-        "x": 398.4582577703355,
-        "y": 761.9160894794041,
+        "x": 578.6680338946361,
+        "y": 773.5910890270244,
         "z": 5000
       },
       "rotation": {
@@ -1280,12 +1280,12 @@
         "z": 0
       },
       "contentRect": {
-        "x": 11.419909393213834,
-        "y": -55.16486820563042,
+        "x": -112.72153476973526,
+        "y": 10.381274310259915,
         "width": 712,
         "height": 785.9612188365651
       },
-      "scale": 0.4521515780898379
+      "scale": 0.5149050783160093
     }
   },
   "camera-uuids": [
@@ -1332,12 +1332,12 @@
     "67c4d4d8-20c3-4295-bcd6-7629b4ae56b4",
     "61f3d9f8-e63d-4508-bbf0-72254266e890",
     "f631c866-c36b-443f-a8c0-a895176b7610",
-    "773de0b0-468b-4fbb-965c-36c47d7a4c94",
     "d6678b55-2635-45df-bdce-51e04632740e",
     "4fac1625-c75a-4a5f-96e6-e15ddac448ae",
     "97847f67-f841-48ad-a6b2-6ac8db2fcbfd",
     "19323c5d-5d36-438a-86ee-8288c690e5b0",
     "9e293cde-e27b-4902-808b-e884f3e9da32",
+    "773de0b0-468b-4fbb-965c-36c47d7a4c94",
     "be14c61f-22d8-4bb9-b444-ad9f29740469"
   ],
   "camera": {

+ 1 - 1
temp/startup.json

@@ -1 +1 @@
-{"pid":24204}
+{"pid":8912}