Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -25,293 +25,287 @@ const GAME_CONSTANTS = {
|
|
| 25 |
|
| 26 |
// μ ν¬κΈ° ν΄λμ€
|
| 27 |
class Fighter {
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
// μλ λ‘€μ μ νλ λ²μ λ΄μμλ§ μλ
|
| 291 |
-
if (Math.abs(this.targetRoll) < maxRollAngle) {
|
| 292 |
-
// λ‘€ κ°λ μ ν μ μ©
|
| 293 |
-
this.targetRoll = Math.max(-maxRollAngle, Math.min(maxRollAngle, this.targetRoll));
|
| 294 |
-
}
|
| 295 |
-
}
|
| 296 |
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
| 315 |
if (!this.mesh) return;
|
| 316 |
|
| 317 |
// λΆλλ¬μ΄ νμ 보κ°
|
|
@@ -529,7 +523,8 @@ class Fighter {
|
|
| 529 |
const gravityAcceleration = GAME_CONSTANTS.GRAVITY * deltaTime * 3.0; // 3λ°° μ€λ ₯
|
| 530 |
this.velocity.y -= gravityAcceleration;
|
| 531 |
}
|
| 532 |
-
|
|
|
|
| 533 |
const noseDirection = new THREE.Vector3(0, 0, 1);
|
| 534 |
|
| 535 |
// μΏΌν°λμΈ κΈ°λ° νμ μμ€ν
|
|
@@ -550,10 +545,11 @@ class Fighter {
|
|
| 550 |
yawQuat.setFromAxisAngle(yAxis, this.rotation.y);
|
| 551 |
rollQuat.setFromAxisAngle(zAxis, this.rotation.z);
|
| 552 |
|
| 553 |
-
// μΏΌν°λμΈ ν©μ± (ν곡기
|
| 554 |
-
|
| 555 |
-
quaternion.multiply(pitchQuat);
|
| 556 |
quaternion.multiply(rollQuat);
|
|
|
|
|
|
|
| 557 |
|
| 558 |
// λ°©ν₯ 벑ν°μ νμ μ μ©
|
| 559 |
noseDirection.applyQuaternion(quaternion);
|
|
@@ -626,10 +622,10 @@ class Fighter {
|
|
| 626 |
meshYawQuat.setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y + 3 * Math.PI / 2);
|
| 627 |
meshRollQuat.setFromAxisAngle(new THREE.Vector3(0, 0, 1), this.rotation.z);
|
| 628 |
|
| 629 |
-
// μΏΌν°λμΈ ν©μ±
|
| 630 |
-
meshQuaternion.multiply(meshYawQuat);
|
| 631 |
-
meshQuaternion.multiply(meshPitchQuat);
|
| 632 |
meshQuaternion.multiply(meshRollQuat);
|
|
|
|
|
|
|
| 633 |
|
| 634 |
this.mesh.quaternion.copy(meshQuaternion);
|
| 635 |
|
|
@@ -680,9 +676,9 @@ class Fighter {
|
|
| 680 |
yawQuat.setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y);
|
| 681 |
rollQuat.setFromAxisAngle(new THREE.Vector3(0, 0, 1), this.rotation.z);
|
| 682 |
|
| 683 |
-
quaternion.multiply(yawQuat);
|
| 684 |
-
quaternion.multiply(pitchQuat);
|
| 685 |
quaternion.multiply(rollQuat);
|
|
|
|
|
|
|
| 686 |
|
| 687 |
muzzleOffset.applyQuaternion(quaternion);
|
| 688 |
bullet.position.copy(this.position).add(muzzleOffset);
|
|
@@ -772,9 +768,9 @@ class Fighter {
|
|
| 772 |
yawQuat.setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y);
|
| 773 |
rollQuat.setFromAxisAngle(new THREE.Vector3(0, 0, 1), this.rotation.z);
|
| 774 |
|
| 775 |
-
quaternion.multiply(yawQuat);
|
| 776 |
-
quaternion.multiply(pitchQuat);
|
| 777 |
quaternion.multiply(rollQuat);
|
|
|
|
|
|
|
| 778 |
|
| 779 |
backward.applyQuaternion(quaternion);
|
| 780 |
up.applyQuaternion(quaternion);
|
|
|
|
| 25 |
|
| 26 |
// μ ν¬κΈ° ν΄λμ€
|
| 27 |
class Fighter {
|
| 28 |
+
constructor() {
|
| 29 |
+
this.mesh = null;
|
| 30 |
+
this.isLoaded = false;
|
| 31 |
+
|
| 32 |
+
// 물리 μμ±
|
| 33 |
+
this.position = new THREE.Vector3(0, 2000, 0);
|
| 34 |
+
this.velocity = new THREE.Vector3(0, 0, 350); // μ΄κΈ° μλ 350kt
|
| 35 |
+
this.acceleration = new THREE.Vector3(0, 0, 0);
|
| 36 |
+
this.rotation = new THREE.Euler(0, 0, 0, 'YXZ'); // ν곡기 νμ€ μ€μΌλ¬ μμ
|
| 37 |
+
|
| 38 |
+
// λΉν μ μ΄
|
| 39 |
+
this.throttle = 0.7; // μ΄κΈ° μ€λ‘ν 70%
|
| 40 |
+
this.speed = 350; // μ΄κΈ° μλ 350kt
|
| 41 |
+
this.altitude = 2000;
|
| 42 |
+
this.gForce = 1.0;
|
| 43 |
+
this.health = GAME_CONSTANTS.MAX_HEALTH; // 체λ ₯ 1000
|
| 44 |
+
|
| 45 |
+
// μ‘°μ’
μ
λ ₯ μμ€ν
|
| 46 |
+
this.pitchInput = 0;
|
| 47 |
+
this.rollInput = 0;
|
| 48 |
+
this.yawInput = 0;
|
| 49 |
+
|
| 50 |
+
// λ§μ°μ€ λμ μ
λ ₯
|
| 51 |
+
this.mousePitch = 0;
|
| 52 |
+
this.mouseRoll = 0;
|
| 53 |
+
|
| 54 |
+
// λΆλλ¬μ΄ νμ μ μν λͺ©νκ°
|
| 55 |
+
this.targetPitch = 0;
|
| 56 |
+
this.targetRoll = 0;
|
| 57 |
+
this.targetYaw = 0;
|
| 58 |
+
|
| 59 |
+
// 무기
|
| 60 |
+
this.missiles = GAME_CONSTANTS.MISSILE_COUNT;
|
| 61 |
+
this.ammo = GAME_CONSTANTS.AMMO_COUNT;
|
| 62 |
+
this.bullets = [];
|
| 63 |
+
this.lastShootTime = 0;
|
| 64 |
+
this.isMouseDown = false; // λ§μ°μ€ λλ¦ μν μΆμ
|
| 65 |
+
this.gunfireAudios = []; // κΈ°κ΄μ΄ μ리 λ°°μ΄ (μ΅λ 5κ°)
|
| 66 |
+
|
| 67 |
+
// μ€ν¨ νμΆμ μν Fν€ μν
|
| 68 |
+
this.escapeKeyPressed = false;
|
| 69 |
+
this.stallEscapeProgress = 0; // μ€ν¨ νμΆ μ§νλ (0~2μ΄)
|
| 70 |
+
|
| 71 |
+
// μΉ΄λ©λΌ μ€μ
|
| 72 |
+
this.cameraDistance = 250;
|
| 73 |
+
this.cameraHeight = 30;
|
| 74 |
+
this.cameraLag = 0.06;
|
| 75 |
+
|
| 76 |
+
// κ²½κ³ μμ€ν
|
| 77 |
+
this.altitudeWarning = false;
|
| 78 |
+
this.stallWarning = false;
|
| 79 |
+
this.warningBlinkTimer = 0;
|
| 80 |
+
this.warningBlinkState = false;
|
| 81 |
+
|
| 82 |
+
// Over-G μμ€ν
|
| 83 |
+
this.overG = false;
|
| 84 |
+
this.maxGForce = 9.0;
|
| 85 |
+
this.overGTimer = 0; // Over-G μ§μ μκ°
|
| 86 |
+
|
| 87 |
+
// κ²½κ³ μ μμ€ν
|
| 88 |
+
this.warningAudios = {
|
| 89 |
+
altitude: null,
|
| 90 |
+
pullup: null,
|
| 91 |
+
overg: null,
|
| 92 |
+
stall: null,
|
| 93 |
+
normal: null // μμ§ μ리
|
| 94 |
+
};
|
| 95 |
+
this.initializeWarningAudios();
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
// ν€λ©μ 0~360λλ‘ μ κ·ννλ ν¬νΌ ν¨μ
|
| 99 |
+
normalizeHeading(radians) {
|
| 100 |
+
let degrees = radians * (180 / Math.PI);
|
| 101 |
+
while (degrees < 0) degrees += 360;
|
| 102 |
+
while (degrees >= 360) degrees -= 360;
|
| 103 |
+
return degrees;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
// λΌλμμ -Ο ~ Ο λ²μλ‘ μ κ·ν
|
| 107 |
+
normalizeAngle(angle) {
|
| 108 |
+
while (angle > Math.PI) angle -= Math.PI * 2;
|
| 109 |
+
while (angle < -Math.PI) angle += Math.PI * 2;
|
| 110 |
+
return angle;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
initializeWarningAudios() {
|
| 114 |
+
try {
|
| 115 |
+
this.warningAudios.altitude = new Audio('sounds/altitude.ogg');
|
| 116 |
+
this.warningAudios.altitude.volume = 0.75;
|
| 117 |
+
|
| 118 |
+
this.warningAudios.pullup = new Audio('sounds/pullup.ogg');
|
| 119 |
+
this.warningAudios.pullup.volume = 0.9;
|
| 120 |
+
|
| 121 |
+
this.warningAudios.overg = new Audio('sounds/overg.ogg');
|
| 122 |
+
this.warningAudios.overg.volume = 0.75;
|
| 123 |
+
|
| 124 |
+
this.warningAudios.stall = new Audio('sounds/alert.ogg');
|
| 125 |
+
this.warningAudios.stall.volume = 0.75;
|
| 126 |
+
|
| 127 |
+
// μμ§ μ리 μ€μ
|
| 128 |
+
this.warningAudios.normal = new Audio('sounds/normal.ogg');
|
| 129 |
+
this.warningAudios.normal.volume = 0.5;
|
| 130 |
+
this.warningAudios.normal.loop = true; // μμ§ μ리λ κ³μ λ°λ³΅
|
| 131 |
+
|
| 132 |
+
// κ²½κ³ μμλ§ ended μ΄λ²€νΈ 리μ€λ μΆκ° (μμ§ μ리 μ μΈ)
|
| 133 |
+
Object.keys(this.warningAudios).forEach(key => {
|
| 134 |
+
if (key !== 'normal' && this.warningAudios[key]) {
|
| 135 |
+
this.warningAudios[key].addEventListener('ended', () => {
|
| 136 |
+
this.updateWarningAudios();
|
| 137 |
+
});
|
| 138 |
+
}
|
| 139 |
+
});
|
| 140 |
+
} catch (e) {
|
| 141 |
+
console.log('Warning audio initialization failed:', e);
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
startEngineSound() {
|
| 146 |
+
// μμ§ μ리 μμ
|
| 147 |
+
if (this.warningAudios.normal) {
|
| 148 |
+
this.warningAudios.normal.play().catch(e => {
|
| 149 |
+
console.log('Engine sound failed to start:', e);
|
| 150 |
+
});
|
| 151 |
+
}
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
updateWarningAudios() {
|
| 155 |
+
let currentWarning = null;
|
| 156 |
+
|
| 157 |
+
if (this.altitude < 250) {
|
| 158 |
+
currentWarning = 'pullup';
|
| 159 |
+
}
|
| 160 |
+
else if (this.altitude < 500) {
|
| 161 |
+
currentWarning = 'altitude';
|
| 162 |
+
}
|
| 163 |
+
else if (this.overG) {
|
| 164 |
+
currentWarning = 'overg';
|
| 165 |
+
}
|
| 166 |
+
else if (this.stallWarning) {
|
| 167 |
+
currentWarning = 'stall';
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// κ²½κ³ μλ§ κ΄λ¦¬ (μμ§ μ리λ μ μΈ)
|
| 171 |
+
Object.keys(this.warningAudios).forEach(key => {
|
| 172 |
+
if (key !== 'normal' && key !== currentWarning && this.warningAudios[key] && !this.warningAudios[key].paused) {
|
| 173 |
+
this.warningAudios[key].pause();
|
| 174 |
+
this.warningAudios[key].currentTime = 0;
|
| 175 |
+
}
|
| 176 |
+
});
|
| 177 |
+
|
| 178 |
+
if (currentWarning && this.warningAudios[currentWarning]) {
|
| 179 |
+
if (this.warningAudios[currentWarning].paused) {
|
| 180 |
+
this.warningAudios[currentWarning].play().catch(e => {});
|
| 181 |
+
}
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
stopAllWarningAudios() {
|
| 186 |
+
// λͺ¨λ μ€λμ€ μ μ§ (μμ§ μ리 ν¬ν¨)
|
| 187 |
+
Object.values(this.warningAudios).forEach(audio => {
|
| 188 |
+
if (audio && !audio.paused) {
|
| 189 |
+
audio.pause();
|
| 190 |
+
audio.currentTime = 0;
|
| 191 |
+
}
|
| 192 |
+
});
|
| 193 |
+
}
|
| 194 |
|
| 195 |
+
async initialize(scene, loader) {
|
| 196 |
+
try {
|
| 197 |
+
const result = await loader.loadAsync('models/f-15.glb');
|
| 198 |
+
this.mesh = result.scene;
|
| 199 |
+
this.mesh.position.copy(this.position);
|
| 200 |
+
this.mesh.scale.set(2, 2, 2);
|
| 201 |
+
this.mesh.rotation.y = Math.PI / 4;
|
| 202 |
+
|
| 203 |
+
this.mesh.traverse((child) => {
|
| 204 |
+
if (child.isMesh) {
|
| 205 |
+
child.castShadow = true;
|
| 206 |
+
child.receiveShadow = true;
|
| 207 |
+
}
|
| 208 |
+
});
|
| 209 |
+
|
| 210 |
+
scene.add(this.mesh);
|
| 211 |
+
this.isLoaded = true;
|
| 212 |
+
console.log('F-15 μ ν¬κΈ° λ‘λ© μλ£');
|
| 213 |
+
} catch (error) {
|
| 214 |
+
console.error('F-15 λͺ¨λΈ λ‘λ© μ€ν¨:', error);
|
| 215 |
+
this.createFallbackModel(scene);
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
|
| 219 |
+
createFallbackModel(scene) {
|
| 220 |
+
const group = new THREE.Group();
|
| 221 |
+
|
| 222 |
+
const fuselageGeometry = new THREE.CylinderGeometry(0.8, 1.5, 12, 8);
|
| 223 |
+
const fuselageMaterial = new THREE.MeshLambertMaterial({ color: 0x606060 });
|
| 224 |
+
const fuselage = new THREE.Mesh(fuselageGeometry, fuselageMaterial);
|
| 225 |
+
fuselage.rotation.x = Math.PI / 2;
|
| 226 |
+
group.add(fuselage);
|
| 227 |
+
|
| 228 |
+
const wingGeometry = new THREE.BoxGeometry(16, 0.3, 4);
|
| 229 |
+
const wingMaterial = new THREE.MeshLambertMaterial({ color: 0x404040 });
|
| 230 |
+
const wings = new THREE.Mesh(wingGeometry, wingMaterial);
|
| 231 |
+
wings.position.z = -1;
|
| 232 |
+
group.add(wings);
|
| 233 |
+
|
| 234 |
+
const tailGeometry = new THREE.BoxGeometry(0.3, 4, 3);
|
| 235 |
+
const tailMaterial = new THREE.MeshLambertMaterial({ color: 0x404040 });
|
| 236 |
+
const tail = new THREE.Mesh(tailGeometry, tailMaterial);
|
| 237 |
+
tail.position.z = -5;
|
| 238 |
+
tail.position.y = 1.5;
|
| 239 |
+
group.add(tail);
|
| 240 |
+
|
| 241 |
+
const horizontalTailGeometry = new THREE.BoxGeometry(6, 0.2, 2);
|
| 242 |
+
const horizontalTail = new THREE.Mesh(horizontalTailGeometry, tailMaterial);
|
| 243 |
+
horizontalTail.position.z = -5;
|
| 244 |
+
horizontalTail.position.y = 0.5;
|
| 245 |
+
group.add(horizontalTail);
|
| 246 |
+
|
| 247 |
+
this.mesh = group;
|
| 248 |
+
this.mesh.position.copy(this.position);
|
| 249 |
+
this.mesh.scale.set(2, 2, 2);
|
| 250 |
+
scene.add(this.mesh);
|
| 251 |
+
this.isLoaded = true;
|
| 252 |
+
|
| 253 |
+
console.log('Fallback μ ν¬κΈ° λͺ¨λΈ μμ± μλ£');
|
| 254 |
+
}
|
| 255 |
|
| 256 |
+
updateMouseInput(deltaX, deltaY) {
|
| 257 |
+
// Over-G μνμμ μ€ν¨μ΄ ν΄μ λμ§ μμμΌλ©΄ νΌμΉ μ‘°μ λΆκ°
|
| 258 |
+
if (this.overG && this.overGTimer > 1.0 && this.stallWarning) {
|
| 259 |
+
// μ(Yaw)λ§ μ νμ μΌλ‘ νμ©
|
| 260 |
+
const sensitivity = GAME_CONSTANTS.MOUSE_SENSITIVITY * 0.3;
|
| 261 |
+
this.targetYaw += deltaX * sensitivity * 0.3;
|
| 262 |
+
return;
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
const sensitivity = GAME_CONSTANTS.MOUSE_SENSITIVITY * 1.0;
|
| 266 |
+
|
| 267 |
+
// λ§μ°μ€ μ
λ ₯μ κ°μλλ‘ λ³ν
|
| 268 |
+
const pitchRate = -deltaY * sensitivity;
|
| 269 |
+
const yawRate = deltaX * sensitivity * 0.8;
|
| 270 |
+
|
| 271 |
+
// νμ¬ μνμμμ νΌμΉ μ ν
|
| 272 |
+
this.targetPitch += pitchRate;
|
| 273 |
+
this.targetYaw += yawRate;
|
| 274 |
+
|
| 275 |
+
// μ νμ μ λ°λ₯Έ μμ°μ€λ¬μ΄ λ±
ν¬ (λ‘€)
|
| 276 |
+
// μ€μ ν곡기μ²λΌ μ ν μ μλμΌλ‘ κΈ°μΈμ΄μ§
|
| 277 |
+
const targetBankAngle = -yawRate * 15; // μ μλμ λΉλ‘ν λ±
ν¬ κ°λ
|
| 278 |
+
|
| 279 |
+
// λ‘€μ λͺ©ν λ±
ν¬ κ°λλ‘ λΆλλ½κ² μ ν
|
| 280 |
+
this.targetRoll = THREE.MathUtils.lerp(this.targetRoll, targetBankAngle, 0.1);
|
| 281 |
+
|
| 282 |
+
// κ°λ μ ν
|
| 283 |
+
const maxPitchAngle = Math.PI / 3; // 60λ
|
| 284 |
+
const maxRollAngle = Math.PI * 0.5; // 90λ
|
| 285 |
+
|
| 286 |
+
this.targetPitch = Math.max(-maxPitchAngle, Math.min(maxPitchAngle, this.targetPitch));
|
| 287 |
+
this.targetRoll = Math.max(-maxRollAngle, Math.min(maxRollAngle, this.targetRoll));
|
| 288 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
+
updateControls(keys, deltaTime) {
|
| 291 |
+
// W/S: μ€λ‘νλ§ μ μ΄ (κ°μ/κ°μ)
|
| 292 |
+
if (keys.w) {
|
| 293 |
+
this.throttle = Math.min(1.0, this.throttle + deltaTime * 0.5);
|
| 294 |
+
}
|
| 295 |
+
if (keys.s) {
|
| 296 |
+
this.throttle = Math.max(0.1, this.throttle - deltaTime * 0.5);
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
// A/D: 보쑰 μ μ μ΄ (λ¬λ) - λ°μμ± κ°μ
|
| 300 |
+
if (keys.a) {
|
| 301 |
+
this.targetYaw -= deltaTime * 1.2;
|
| 302 |
+
}
|
| 303 |
+
if (keys.d) {
|
| 304 |
+
this.targetYaw += deltaTime * 1.2;
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
updatePhysics(deltaTime) {
|
| 309 |
if (!this.mesh) return;
|
| 310 |
|
| 311 |
// λΆλλ¬μ΄ νμ 보κ°
|
|
|
|
| 523 |
const gravityAcceleration = GAME_CONSTANTS.GRAVITY * deltaTime * 3.0; // 3λ°° μ€λ ₯
|
| 524 |
this.velocity.y -= gravityAcceleration;
|
| 525 |
}
|
| 526 |
+
|
| 527 |
+
// μλ λ²‘ν° κ³μ° - μΏΌν°λμΈμ μ¬μ©νμ¬ μ§λ² λ½ μμ ννΌ
|
| 528 |
const noseDirection = new THREE.Vector3(0, 0, 1);
|
| 529 |
|
| 530 |
// μΏΌν°λμΈ κΈ°λ° νμ μμ€ν
|
|
|
|
| 545 |
yawQuat.setFromAxisAngle(yAxis, this.rotation.y);
|
| 546 |
rollQuat.setFromAxisAngle(zAxis, this.rotation.z);
|
| 547 |
|
| 548 |
+
// μΏΌν°λμΈ ν©μ± (μ¬λ°λ₯Έ ν곡기 μμ: Roll -> Pitch -> Yaw)
|
| 549 |
+
// ν곡기λ λ¨Όμ λ‘€, κ·Έ λ€μ νΌμΉ, λ§μ§λ§μΌλ‘ μ μμλ‘ νμ
|
|
|
|
| 550 |
quaternion.multiply(rollQuat);
|
| 551 |
+
quaternion.multiply(pitchQuat);
|
| 552 |
+
quaternion.multiply(yawQuat);
|
| 553 |
|
| 554 |
// λ°©ν₯ 벑ν°μ νμ μ μ©
|
| 555 |
noseDirection.applyQuaternion(quaternion);
|
|
|
|
| 622 |
meshYawQuat.setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y + 3 * Math.PI / 2);
|
| 623 |
meshRollQuat.setFromAxisAngle(new THREE.Vector3(0, 0, 1), this.rotation.z);
|
| 624 |
|
| 625 |
+
// μΏΌν°λμΈ ν©μ± (μ¬λ°λ₯Έ μμ)
|
|
|
|
|
|
|
| 626 |
meshQuaternion.multiply(meshRollQuat);
|
| 627 |
+
meshQuaternion.multiply(meshPitchQuat);
|
| 628 |
+
meshQuaternion.multiply(meshYawQuat);
|
| 629 |
|
| 630 |
this.mesh.quaternion.copy(meshQuaternion);
|
| 631 |
|
|
|
|
| 676 |
yawQuat.setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y);
|
| 677 |
rollQuat.setFromAxisAngle(new THREE.Vector3(0, 0, 1), this.rotation.z);
|
| 678 |
|
|
|
|
|
|
|
| 679 |
quaternion.multiply(rollQuat);
|
| 680 |
+
quaternion.multiply(pitchQuat);
|
| 681 |
+
quaternion.multiply(yawQuat);
|
| 682 |
|
| 683 |
muzzleOffset.applyQuaternion(quaternion);
|
| 684 |
bullet.position.copy(this.position).add(muzzleOffset);
|
|
|
|
| 768 |
yawQuat.setFromAxisAngle(new THREE.Vector3(0, 1, 0), this.rotation.y);
|
| 769 |
rollQuat.setFromAxisAngle(new THREE.Vector3(0, 0, 1), this.rotation.z);
|
| 770 |
|
|
|
|
|
|
|
| 771 |
quaternion.multiply(rollQuat);
|
| 772 |
+
quaternion.multiply(pitchQuat);
|
| 773 |
+
quaternion.multiply(yawQuat);
|
| 774 |
|
| 775 |
backward.applyQuaternion(quaternion);
|
| 776 |
up.applyQuaternion(quaternion);
|