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

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +15 -10
game.js CHANGED
@@ -1945,18 +1945,23 @@ this.enemies.forEach(enemy => {
1945
  }
1946
  // ν¬λ‘œμŠ€ν—€μ–΄ μ—…λ°μ΄νŠΈ λ©”μ„œλ“œ μΆ”κ°€
1947
  updateCrosshair() {
1948
- this.raycaster.setFromCamera(new THREE.Vector2(), this.camera);
 
 
1949
 
1950
- // 적 μ „μ°¨λ“€μ˜ λ©”μ‹œλ§Œ ν¬ν•¨ν•˜λŠ” λ°°μ—΄ 생성
1951
- const enemyMeshes = this.enemies
1952
- .filter(enemy => enemy.mesh && enemy.isLoaded)
1953
- .map(enemy => enemy.mesh);
1954
-
1955
- // 적 전차에 λŒ€ν•΄μ„œλ§Œ 레이캐슀트 μˆ˜ν–‰
1956
- const intersects = this.raycaster.intersectObjects(enemyMeshes, true);
 
 
 
 
1957
 
1958
- // ꡐ차점이 있으면 ν¬λ‘œμŠ€ν—€μ–΄ 색상 λ³€κ²½
1959
- if (intersects.length > 0) {
1960
  this.crosshair.classList.add('target-detected');
1961
  } else {
1962
  this.crosshair.classList.remove('target-detected');
 
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');