fix(player): порт — бластер от 3-го лица стреляет в точку клика

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
min 2026-06-07 14:01:15 +03:00
parent 909af7a5d8
commit d36059e5ce

View File

@ -90,6 +90,17 @@ export class WeaponSystem {
if (e.button !== 0) return;
// Если UI-режим курсора — не стреляем (мышь работает по GUI)
if (this.scene3d?.player?.isUiCursorMode?.()) return;
// Свободный курсор (нет pointer-lock, обычно 3-е лицо) → стрелять туда,
// куда кликнули, а не в центр камеры.
if (document.pointerLockElement !== canvas) {
const rect = canvas.getBoundingClientRect();
const cx = (e.clientX != null ? e.clientX : 0) - rect.left;
const cy = (e.clientY != null ? e.clientY : 0) - rect.top;
if (cx >= 0 && cy >= 0 && cx <= rect.width && cy <= rect.height) {
this.setAimScreenPoint(cx * (canvas.width / rect.width),
cy * (canvas.height / rect.height));
}
}
this._mouseDown = true;
this._tryFire();
};
@ -97,14 +108,26 @@ export class WeaponSystem {
if (e.button !== 0) return;
this._mouseDown = false;
};
const onMove = (e) => {
if (!this._mouseDown) return;
if (document.pointerLockElement === canvas) return;
const rect = canvas.getBoundingClientRect();
const cx = (e.clientX != null ? e.clientX : 0) - rect.left;
const cy = (e.clientY != null ? e.clientY : 0) - rect.top;
if (cx >= 0 && cy >= 0 && cx <= rect.width && cy <= rect.height) {
this._holdAim = { x: cx * (canvas.width / rect.width), y: cy * (canvas.height / rect.height) };
}
};
const onKey = (e) => {
if (e.code === 'KeyR') this.reload();
};
canvas.addEventListener('mousedown', onDown);
window.addEventListener('mouseup', onUp);
window.addEventListener('mousemove', onMove);
window.addEventListener('keydown', onKey);
this._listeners.push({ target: canvas, type: 'mousedown', fn: onDown });
this._listeners.push({ target: window, type: 'mouseup', fn: onUp });
this._listeners.push({ target: window, type: 'mousemove', fn: onMove });
this._listeners.push({ target: window, type: 'keydown', fn: onKey });
// Регистрируем перед-кадровый хук для авто-стрельбы (если auto=true)
@ -583,7 +606,10 @@ export class WeaponSystem {
// (для tap-to-shoot на мобиле). Точка применяется один раз.
let hit = null;
let ray;
const aim = this._aimScreenPoint;
let aim = this._aimScreenPoint;
if (!aim && this._holdAim && document.pointerLockElement !== this.scene3d?.canvas) {
aim = this._holdAim;
}
try {
if (aim) {
ray = this.scene.createPickingRay(aim.x, aim.y, null, camera);