Spaces:
Running
Running
cutechicken
commited on
Commit
โข
3cdb2ea
1
Parent(s):
e5248b4
Update game.js
Browse files
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 |
-
|
2110 |
-
|
2111 |
-
|
2112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|