123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- System.register(["cc"], function (_export, _context) {
- "use strict";
- var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, math, randomRange, Vec3, _dec, _class, _crd, ccclass, property, PlayerCamera;
- return {
- setters: [function (_cc) {
- _cclegacy = _cc.cclegacy;
- __checkObsolete__ = _cc.__checkObsolete__;
- __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
- _decorator = _cc._decorator;
- Component = _cc.Component;
- math = _cc.math;
- randomRange = _cc.randomRange;
- Vec3 = _cc.Vec3;
- }],
- execute: function () {
- _crd = true;
- _cclegacy._RF.push({}, "619d01JKG1NDJ7W6p8rn+AL", "PlayerCamera", undefined);
- __checkObsolete__(['_decorator', 'Component', 'math', 'Node', 'randomRange', 'Vec3']);
- ({
- ccclass,
- property
- } = _decorator);
- _export("PlayerCamera", PlayerCamera = (_dec = ccclass('PlayerCamera'), _dec(_class = class PlayerCamera extends Component {
- constructor() {
- super(...arguments);
- /** 是否允许相机抖动 */
- this.canShake = true;
- /** 抖动持续时间 */
- this.duration = 0;
- /** 已过去的时间 */
- this.elapsed = 0;
- /** 计时器 */
- this.timer = 0;
- /** 相机原始位置 */
- this.originalPos = new Vec3();
- /** 抖动幅度 */
- this.shakeAmplitude = 1;
- // 新增Z轴震动参数
- this.targetZ = 0;
- this.startZ = 0;
- }
- /**
- * 组件开始运行时调用,记录相机的原始位置
- */
- start() {
- this.originalPos = this.node.position.clone();
- }
- /**
- * 触发相机抖动(新增Z轴参数)
- * @param duration - 抖动持续时间
- * @param amplitude - XY轴抖动幅度
- * @param zAmplitude - Z轴后坐力幅度
- */
- shake(duration, amplitude, zAmplitude) {
- if (zAmplitude === void 0) {
- zAmplitude = 0;
- }
- if (this.canShake) return;
- this.canShake = true;
- this.duration = duration;
- this.shakeAmplitude = amplitude; // 记录Z轴初始位置并计算目标位置
- this.startZ = this.node.position.z;
- this.targetZ = this.startZ + zAmplitude;
- this.elapsed = 0;
- }
- update(deltaTime) {
- if (!this.canShake) {
- this.node.position = this.originalPos;
- return;
- }
- this.elapsed += deltaTime;
- var progress = Math.min(this.elapsed / this.duration, 1); //线性插值计算Z轴位置
- var currentZ = math.lerp(this.startZ, this.targetZ, this.easeOutQuad(progress)); //XY轴保持随机抖动
- var xOffset = randomRange(-this.shakeAmplitude, this.shakeAmplitude);
- var yOffset = randomRange(-this.shakeAmplitude, this.shakeAmplitude);
- this.node.setPosition(this.originalPos.x + xOffset, this.originalPos.y + yOffset, currentZ);
- if (progress >= 1) {
- this.canShake = false; //最终确保回到精确的原始位置
- this.node.setPosition(this.originalPos.x, this.originalPos.y, this.startZ);
- }
- }
- /** 二次缓动函数 */
- easeOutQuad(t) {
- return t * (2 - t);
- }
- }) || _class));
- _cclegacy._RF.pop();
- _crd = false;
- }
- };
- });
- //# sourceMappingURL=784ba4a54c928038eb170ee09ab498f2db8046f7.js.map
|