cutechicken commited on
Commit
b9015a6
β€’
1 Parent(s): e37b3e1

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +11 -15
game.js CHANGED
@@ -1945,23 +1945,19 @@ this.enemies.forEach(enemy => {
1945
  }
1946
  // ν¬λ‘œμŠ€ν—€μ–΄ μ—…λ°μ΄νŠΈ λ©”μ„œλ“œ μΆ”κ°€
1947
  updateCrosshair() {
1948
- // ν™”λ©΄ μ€‘μ•™μ—μ„œ μ•½κ°„μ˜ μ—¬μœ λ₯Ό 두고 λ ˆμ΄μΊμŠ€νŒ…
1949
- const raycasterDirection = new THREE.Vector2();
1950
- this.raycaster.setFromCamera(raycasterDirection, this.camera);
1951
 
1952
- // 적 μ „μ°¨μ˜ λ°”μš΄λ”© λ°•μŠ€λ„ ν¬ν•¨ν•˜μ—¬ 검사
1953
- const detectEnemy = this.enemies.some(enemy => {
1954
- if (!enemy.mesh || !enemy.isLoaded) return false;
1955
-
1956
- // 적 μ „μ°¨μ˜ λ°”μš΄λ”© λ°•μŠ€ 생성
1957
- const boundingBox = new THREE.Box3().setFromObject(enemy.mesh);
1958
- const intersects = this.raycaster.ray.intersectsBox(boundingBox);
1959
-
1960
- // λ°”μš΄λ”© λ°•μŠ€μ™€μ˜ ꡐ차 μ—¬λΆ€λ‘œ νŒλ‹¨
1961
- return intersects;
1962
- });
1963
 
1964
- if (detectEnemy) {
 
1965
  this.crosshair.classList.add('target-detected');
1966
  } else {
1967
  this.crosshair.classList.remove('target-detected');
 
1945
  }
1946
  // ν¬λ‘œμŠ€ν—€μ–΄ μ—…λ°μ΄νŠΈ λ©”μ„œλ“œ μΆ”κ°€
1947
  updateCrosshair() {
1948
+ // ν™”λ©΄ 쀑앙 μ’Œν‘œλ₯Ό μ‚¬μš©ν•˜λŠ” λ ˆμ΄μΊμŠ€ν„° 생성
1949
+ this.raycaster.setFromCamera(new THREE.Vector2(0, 0), this.camera);
 
1950
 
1951
+ // 적 μ „μ°¨ λ©”μ‹œλ“€λ§Œ λͺ¨μ•„μ„œ λ°°μ—΄ 생성
1952
+ const enemyMeshes = this.enemies
1953
+ .filter(enemy => enemy.mesh && enemy.isLoaded)
1954
+ .map(enemy => enemy.mesh);
1955
+
1956
+ // λ ˆμ΄μ™€ 적 μ „μ°¨ λ©”μ‹œλ“€μ˜ ꡐ차 검사
1957
+ const intersects = this.raycaster.intersectObjects(enemyMeshes, true);
 
 
 
 
1958
 
1959
+ // ꡐ차점이 있으면 ν¬λ‘œμŠ€ν—€μ–΄ μƒνƒœ λ³€κ²½
1960
+ if (intersects.length > 0) {
1961
  this.crosshair.classList.add('target-detected');
1962
  } else {
1963
  this.crosshair.classList.remove('target-detected');