fix(map): add world plane collision and respawn
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import { TERRAIN_BOUNDARY_CONFIG } from "@/data/world/terrainBoundaryConfig";
|
||||
|
||||
function createBoundarySegments(): React.JSX.Element[] {
|
||||
const segments: React.JSX.Element[] = [];
|
||||
const {
|
||||
center,
|
||||
height,
|
||||
radius,
|
||||
segments: segmentCount,
|
||||
thickness,
|
||||
} = TERRAIN_BOUNDARY_CONFIG;
|
||||
const arcLength = (Math.PI * 2 * radius) / segmentCount;
|
||||
|
||||
for (let index = 0; index < segmentCount; index++) {
|
||||
const angle = (index / segmentCount) * Math.PI * 2;
|
||||
const x = center[0] + Math.cos(angle) * radius;
|
||||
const z = center[2] + Math.sin(angle) * radius;
|
||||
|
||||
segments.push(
|
||||
<mesh key={index} position={[x, center[1], z]} rotation={[0, -angle, 0]}>
|
||||
<boxGeometry args={[arcLength, height, thickness]} />
|
||||
<meshBasicMaterial />
|
||||
</mesh>,
|
||||
);
|
||||
}
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
export function TerrainBoundaryCollision(): React.JSX.Element | null {
|
||||
if (!TERRAIN_BOUNDARY_CONFIG.enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <>{createBoundarySegments()}</>;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { WorldPlaneCollision } from "@/world/collision/WorldPlaneCollision";
|
||||
import { WorldWallsCollision } from "@/world/collision/WorldWallsCollision";
|
||||
|
||||
export function WorldBoundsCollision(): React.JSX.Element {
|
||||
return (
|
||||
<group name="world-bounds-collision">
|
||||
<WorldPlaneCollision />
|
||||
<WorldWallsCollision />
|
||||
</group>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { WORLD_BOUNDS_CONFIG } from "@/data/world/worldBoundsConfig";
|
||||
|
||||
export function WorldPlaneCollision(): React.JSX.Element | null {
|
||||
if (!WORLD_BOUNDS_CONFIG.enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { center, planeCollisionThickness, planeY, size } = WORLD_BOUNDS_CONFIG;
|
||||
const [width, depth] = size;
|
||||
|
||||
return (
|
||||
<mesh
|
||||
name="world-plane-collision"
|
||||
position={[center[0], planeY - planeCollisionThickness / 2, center[2]]}
|
||||
>
|
||||
<boxGeometry args={[width, planeCollisionThickness, depth]} />
|
||||
<meshBasicMaterial />
|
||||
</mesh>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { WORLD_BOUNDS_CONFIG } from "@/data/world/worldBoundsConfig";
|
||||
|
||||
export function WorldWallsCollision(): React.JSX.Element | null {
|
||||
if (!WORLD_BOUNDS_CONFIG.enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { center, size, wallHeight, wallThickness } = WORLD_BOUNDS_CONFIG;
|
||||
const [width, depth] = size;
|
||||
const wallY = center[1] + wallHeight / 2;
|
||||
const halfWidth = width / 2;
|
||||
const halfDepth = depth / 2;
|
||||
|
||||
return (
|
||||
<group name="world-walls-collision">
|
||||
<mesh position={[center[0], wallY, center[2] - halfDepth]}>
|
||||
<boxGeometry
|
||||
args={[width + wallThickness * 2, wallHeight, wallThickness]}
|
||||
/>
|
||||
<meshBasicMaterial />
|
||||
</mesh>
|
||||
<mesh position={[center[0], wallY, center[2] + halfDepth]}>
|
||||
<boxGeometry
|
||||
args={[width + wallThickness * 2, wallHeight, wallThickness]}
|
||||
/>
|
||||
<meshBasicMaterial />
|
||||
</mesh>
|
||||
<mesh position={[center[0] - halfWidth, wallY, center[2]]}>
|
||||
<boxGeometry args={[wallThickness, wallHeight, depth]} />
|
||||
<meshBasicMaterial />
|
||||
</mesh>
|
||||
<mesh position={[center[0] + halfWidth, wallY, center[2]]}>
|
||||
<boxGeometry args={[wallThickness, wallHeight, depth]} />
|
||||
<meshBasicMaterial />
|
||||
</mesh>
|
||||
</group>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user