cutechicken commited on
Commit
3cdb2ea
โ€ข
1 Parent(s): e5248b4

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +21 -7
game.js CHANGED
@@ -2103,16 +2103,30 @@ class Game {
2103
 
2104
  const tankPosition = this.tank.getPosition();
2105
  const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
 
 
2106
 
2107
- // ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ (๊ฐœ์„ )
2108
  this.obstacles.forEach(obstacle => {
2109
- if (obstacle.userData.isCollidable) { // ์ถฉ๋Œ ๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด๋งŒ ๊ฒ€์‚ฌ
2110
- const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
2111
- if (tankBoundingBox.intersectsBox(obstacleBoundingBox)) {
2112
- this.tank.body.position.copy(this.previousTankPosition);
 
 
 
 
 
 
 
 
 
 
 
 
2113
  }
2114
- }
2115
- });
2116
  // ์  ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ (์ถ”๊ฐ€)
2117
  this.enemies.forEach(enemy => {
2118
  if (!enemy.mesh || !enemy.isLoaded) return;
 
2103
 
2104
  const tankPosition = this.tank.getPosition();
2105
  const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
2106
+ // ์ด์ „ ์œ„์น˜๋ฅผ ์ €์žฅ
2107
+ const previousPosition = this.tank.body.position.clone();
2108
 
2109
+ // ์ถฉ๋Œ ๊ฒ€์‚ฌ
2110
  this.obstacles.forEach(obstacle => {
2111
+ if (obstacle.userData.isCollidable) {
2112
+ const obstacleBoundingBox = new THREE.Box3().setFromObject(obstacle);
2113
+ const tankBoundingBox = new THREE.Box3().setFromObject(this.tank.body);
2114
+
2115
+ if (tankBoundingBox.intersectsBox(obstacleBoundingBox)) {
2116
+ // ์ถฉ๋Œํ•œ ๋ฐฉํ–ฅ์œผ๋กœ์˜ ์ด๋™๋งŒ ์ฐจ๋‹จ
2117
+ const collisionNormal = new THREE.Vector3()
2118
+ .subVectors(this.tank.body.position, obstacle.position)
2119
+ .normalize();
2120
+
2121
+ const correctionVector = collisionNormal.multiplyScalar(0.5); // ์ถฉ๋Œ ๋ฐฉํ–ฅ์œผ๋กœ ๋ฐ€๊ธฐ
2122
+ this.tank.body.position.add(correctionVector);
2123
+
2124
+ // ์ด์ „ ์œ„์น˜ ์ €์žฅ
2125
+ this.previousTankPosition.copy(previousPosition);
2126
+ }
2127
  }
2128
+ });
2129
+ //}
2130
  // ์  ํƒฑํฌ์™€ ์žฅ์• ๋ฌผ ์ถฉ๋Œ ์ฒดํฌ (์ถ”๊ฐ€)
2131
  this.enemies.forEach(enemy => {
2132
  if (!enemy.mesh || !enemy.isLoaded) return;