Browse Source

相机对准目标节点调整

woso_javan 1 month ago
parent
commit
274ddf1438
1 changed files with 6 additions and 0 deletions
  1. 6 0
      assets/module_aliens/Script/Components/ScreenShotComponent.ts

+ 6 - 0
assets/module_aliens/Script/Components/ScreenShotComponent.ts

@@ -67,6 +67,12 @@ export class ScreenShotComponent extends Component {
 
             // 移动相机对准目标节点
             const targetPos = targetNode.worldPosition.clone();
+            // 计算相机新位置:从目标位置向后移动2个单位
+            const cameraOffset = new Vec3(0, 0, 10); // 调整这个值可以改变相机距离
+            const cameraPos = new Vec3();
+            Vec3.add(cameraPos, targetPos, cameraOffset);
+
+            camera.node.setWorldPosition(cameraPos);
             camera.node.lookAt(targetPos, Vec3.UP);
             camera.targetTexture = renderTex;