Spaces:
Running
Running
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;
|