|
@@ -20,17 +20,18 @@ export class LevelAction extends Component {
|
|
|
private _cameraOriginalPos: Vec3 = v3();
|
|
|
private _touchStartPos: Vec3 = v3();
|
|
|
private _isDragging = false;
|
|
|
+ private _isZooming = false;
|
|
|
public targetNode: Node = null!;
|
|
|
|
|
|
// 添加旋转限制属性
|
|
|
- @property({type: Number})
|
|
|
+ @property({type: Number,displayName:"相机X轴最小旋转角度(上下)"})
|
|
|
public minXRotation: number = -30; // X轴最小旋转角度(上下)
|
|
|
- @property({type: Number})
|
|
|
+ @property({type: Number,displayName:"相机X轴最大旋转角度(上下)"})
|
|
|
public maxXRotation: number = 30; // X轴最大旋转角度(上下)
|
|
|
- @property({type: Number})
|
|
|
- public minYRotation: number = -70; // Y轴最小旋转角度(左右)
|
|
|
- @property({type: Number})
|
|
|
- public maxYRotation: number = 70; // Y轴最大旋转角度(左右)
|
|
|
+ @property({type: Number,displayName:"相机Y轴最小旋转角度(左右)"})
|
|
|
+ public minYRotation: number = -50; // Y轴最小旋转角度(左右)
|
|
|
+ @property({type: Number,displayName:"相机Y轴最大旋转角度(左右)"})
|
|
|
+ public maxYRotation: number = 50; // Y轴最大旋转角度(左右)
|
|
|
private _originalRotation: Vec3 = v3();
|
|
|
|
|
|
//镜头拉近属性
|
|
@@ -116,6 +117,9 @@ export class LevelAction extends Component {
|
|
|
}
|
|
|
|
|
|
private moveCameraAlongForward(distance: number) {
|
|
|
+ if(this._isZooming) return;
|
|
|
+
|
|
|
+ this._isZooming = true;
|
|
|
const currentPos = this.camera.node.position.clone();
|
|
|
const forward = this.camera.node.forward.negative();
|
|
|
const targetPos = currentPos.add(forward.multiplyScalar(distance));
|
|
@@ -125,15 +129,27 @@ export class LevelAction extends Component {
|
|
|
easing: 'smooth',
|
|
|
onUpdate: (target: Vec3) => {
|
|
|
this.camera.node.position = target;
|
|
|
- // 根据距离动态调整旋转限制范围
|
|
|
- const zoomFactor = Math.abs(distance) / 30;
|
|
|
- this.minYRotation = -70 * zoomFactor;
|
|
|
- this.maxYRotation = 70 * zoomFactor;
|
|
|
+ // 根据镜头距离动态调整旋转限制
|
|
|
+ this.adjustRotationLimits();
|
|
|
+ this._isZooming = false;
|
|
|
}
|
|
|
})
|
|
|
.start();
|
|
|
}
|
|
|
|
|
|
+ private adjustRotationLimits() {
|
|
|
+ // 计算当前镜头距离比例 (0-1范围)
|
|
|
+ const distanceRatio = Math.min(1, Math.max(0, (this.camera.node.position.z - this._cameraOriginalPos.z) / -30));
|
|
|
+
|
|
|
+ // 动态调整旋转限制范围
|
|
|
+ const dynamicMinY = this.minYRotation * (1 + distanceRatio);
|
|
|
+ const dynamicMaxY = this.maxYRotation * (1 + distanceRatio);
|
|
|
+
|
|
|
+ // 应用调整后的限制
|
|
|
+ this.minYRotation = dynamicMinY;
|
|
|
+ this.maxYRotation = dynamicMaxY;
|
|
|
+ }
|
|
|
+
|
|
|
/***************************触摸事件**********************************/
|
|
|
private _onTouchStart(event: EventTouch) {
|
|
|
const touchPos = event.getLocation();
|
|
@@ -150,18 +166,10 @@ export class LevelAction extends Component {
|
|
|
const deltaX = currentPos.x - this._touchStartPos.x;
|
|
|
const deltaY = currentPos.y - this._touchStartPos.y;
|
|
|
|
|
|
- // 根据当前相机距离调整旋转灵敏度
|
|
|
- const distanceFactor = Math.max(0.5, this.camera.node.position.length() / 30);
|
|
|
- const sensitivity = 0.1 * distanceFactor;
|
|
|
-
|
|
|
- const rotationDelta = v3(
|
|
|
- deltaY * sensitivity,
|
|
|
- -deltaX * sensitivity,
|
|
|
- 0
|
|
|
- );
|
|
|
-
|
|
|
- // 计算新旋转角度
|
|
|
- const newRotation = this._originalRotation.clone().add(rotationDelta);
|
|
|
+ // 仅计算旋转角度变化
|
|
|
+ const newRotation = this._originalRotation.clone();
|
|
|
+ newRotation.y = this._originalRotation.y - deltaX * 0.2;
|
|
|
+ newRotation.x = this._originalRotation.x + deltaY * 0.2;
|
|
|
|
|
|
// 添加旋转限制
|
|
|
newRotation.x = Math.max(this.minXRotation, Math.min(this.maxXRotation, newRotation.x));
|