Spaces:
Running
Running
cutechicken
commited on
Commit
โข
522c84b
1
Parent(s):
c7fc102
Update game.js
Browse files
game.js
CHANGED
@@ -836,21 +836,6 @@ class Enemy {
|
|
836 |
this.adjustTankTilt();
|
837 |
}
|
838 |
|
839 |
-
checkLineOfSight(targetPosition) {
|
840 |
-
if (!this.mesh) return false;
|
841 |
-
|
842 |
-
const startPos = this.mesh.position.clone();
|
843 |
-
startPos.y += 2; // ํฌํ ๋์ด
|
844 |
-
const direction = new THREE.Vector3()
|
845 |
-
.subVectors(targetPosition, startPos)
|
846 |
-
.normalize();
|
847 |
-
const distance = startPos.distanceTo(targetPosition);
|
848 |
-
|
849 |
-
const raycaster = new THREE.Raycaster(startPos, direction, 0, distance);
|
850 |
-
const intersects = raycaster.intersectObjects(window.gameInstance.obstacles, true);
|
851 |
-
|
852 |
-
return intersects.length === 0;
|
853 |
-
}
|
854 |
|
855 |
findAlternativePath(playerPosition) {
|
856 |
const currentPos = this.mesh.position.clone();
|
@@ -887,13 +872,6 @@ findAlternativePath(playerPosition) {
|
|
887 |
return null;
|
888 |
}
|
889 |
|
890 |
-
checkPathClear(start, end) {
|
891 |
-
const direction = new THREE.Vector3().subVectors(end, start).normalize();
|
892 |
-
const distance = start.distanceTo(end);
|
893 |
-
const raycaster = new THREE.Raycaster(start, direction, 0, distance);
|
894 |
-
const intersects = raycaster.intersectObjects(window.gameInstance.obstacles, true);
|
895 |
-
return intersects.length === 0;
|
896 |
-
}
|
897 |
|
898 |
async initialize(loader) {
|
899 |
try {
|
@@ -936,41 +914,6 @@ checkPathClear(start, end) {
|
|
936 |
// ์ฅ์ ๋ฌผ์ด ์์ ๊ฒฝ์ฐ false ๋ฐํ
|
937 |
return intersects.length === 0;
|
938 |
}
|
939 |
-
// ๋์ฒด ๊ฒฝ๋ก ์ฐพ๊ธฐ ๋ฉ์๋
|
940 |
-
findAlternativePath(playerPosition) {
|
941 |
-
const currentPos = this.mesh.position.clone();
|
942 |
-
const directionToPlayer = new THREE.Vector3()
|
943 |
-
.subVectors(playerPosition, currentPos)
|
944 |
-
.normalize();
|
945 |
-
|
946 |
-
// ์ข์ฐ 90๋ ๋ฐฉํฅ ๊ณ์ฐ
|
947 |
-
const leftDirection = new THREE.Vector3()
|
948 |
-
.copy(directionToPlayer)
|
949 |
-
.applyAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI / 2);
|
950 |
-
const rightDirection = new THREE.Vector3()
|
951 |
-
.copy(directionToPlayer)
|
952 |
-
.applyAxisAngle(new THREE.Vector3(0, 1, 0), -Math.PI / 2);
|
953 |
-
|
954 |
-
// ์ข์ฐ 30๋ฏธํฐ ์ง์ ํ์ธ
|
955 |
-
const checkDistance = 30;
|
956 |
-
const leftPoint = currentPos.clone().add(leftDirection.multiplyScalar(checkDistance));
|
957 |
-
const rightPoint = currentPos.clone().add(rightDirection.multiplyScalar(checkDistance));
|
958 |
-
|
959 |
-
// ๊ฐ ๋ฐฉํฅ์ ์ฅ์ ๋ฌผ ์ฒดํฌ
|
960 |
-
const leftClear = this.checkPathClear(currentPos, leftPoint);
|
961 |
-
const rightClear = this.checkPathClear(currentPos, rightPoint);
|
962 |
-
|
963 |
-
if (leftClear && rightClear) {
|
964 |
-
// ๋ ๋ค ๊ฐ๋ฅํ๋ฉด ๋๋ค ์ ํ
|
965 |
-
return Math.random() < 0.5 ? leftPoint : rightPoint;
|
966 |
-
} else if (leftClear) {
|
967 |
-
return leftPoint;
|
968 |
-
} else if (rightClear) {
|
969 |
-
return rightPoint;
|
970 |
-
}
|
971 |
-
|
972 |
-
return null;
|
973 |
-
}
|
974 |
// ๊ฒฝ๋ก ์ ํจ์ฑ ํ์ธ
|
975 |
checkPathClear(start, end) {
|
976 |
const direction = new THREE.Vector3().subVectors(end, start).normalize();
|
|
|
836 |
this.adjustTankTilt();
|
837 |
}
|
838 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
839 |
|
840 |
findAlternativePath(playerPosition) {
|
841 |
const currentPos = this.mesh.position.clone();
|
|
|
872 |
return null;
|
873 |
}
|
874 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
875 |
|
876 |
async initialize(loader) {
|
877 |
try {
|
|
|
914 |
// ์ฅ์ ๋ฌผ์ด ์์ ๊ฒฝ์ฐ false ๋ฐํ
|
915 |
return intersects.length === 0;
|
916 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
917 |
// ๊ฒฝ๋ก ์ ํจ์ฑ ํ์ธ
|
918 |
checkPathClear(start, end) {
|
919 |
const direction = new THREE.Vector3().subVectors(end, start).normalize();
|