cutechicken commited on
Commit
980bb87
ยท
verified ยท
1 Parent(s): 475b62f

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +9 -15
game.js CHANGED
@@ -1946,23 +1946,17 @@ this.enemies.forEach(enemy => {
1946
  // ํฌ๋กœ์Šคํ—ค์–ด ์—…๋ฐ์ดํŠธ ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
1947
  updateCrosshair() {
1948
  this.raycaster.setFromCamera(new THREE.Vector2(), this.camera);
1949
- const intersects = this.raycaster.intersectObjects(this.scene.children, true);
1950
 
1951
- // ์ถฉ๋Œํ•œ ๊ฐ์ฒด๋“ค ์ค‘ ์  ์ „์ฐจ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ
1952
- const hasEnemyTank = intersects.some(intersect => {
1953
- // ๊ต์ฐจํ•œ ๊ฐ์ฒด๋‚˜ ๊ทธ ๋ถ€๋ชจ ๊ฐ์ฒด ์ค‘์— ์  ์ „์ฐจ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ
1954
- let current = intersect.object;
1955
- while (current) {
1956
- // enemies ๋ฐฐ์—ด์— ์žˆ๋Š” ๋ฉ”์‹œ์™€ ๋น„๊ต
1957
- if (this.enemies.some(enemy => enemy.mesh === current)) {
1958
- return true;
1959
- }
1960
- current = current.parent;
1961
- }
1962
- return false;
1963
- });
1964
 
1965
- if (hasEnemyTank) {
 
1966
  this.crosshair.classList.add('target-detected');
1967
  } else {
1968
  this.crosshair.classList.remove('target-detected');
 
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');