initial commit
This commit is contained in:
commit
c2bb3893a9
1038 changed files with 75846 additions and 0 deletions
26
grid.gd
Normal file
26
grid.gd
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class_name Grid
|
||||
## Central grid constants and utilities for the dungeon crawler.
|
||||
## Cell size: 64x64x128 TrenchBroom units = 2x2x4 Godot units.
|
||||
|
||||
## Size of one grid cell in world units (64 TrenchBroom units).
|
||||
const CELL_SIZE: float = 2.0
|
||||
## Half-cell offset. Cell centers sit halfway between wall planes, so with TB
|
||||
## walls on the 64-unit grid (even Godot units) cell centers land on odd units.
|
||||
const HALF_CELL: float = CELL_SIZE * 0.5
|
||||
|
||||
|
||||
## Snap a world position to the nearest cell center (Y axis unchanged).
|
||||
static func snap(pos: Vector3) -> Vector3:
|
||||
return Vector3(
|
||||
floorf(pos.x / CELL_SIZE) * CELL_SIZE + HALF_CELL,
|
||||
pos.y,
|
||||
floorf(pos.z / CELL_SIZE) * CELL_SIZE + HALF_CELL,
|
||||
)
|
||||
|
||||
|
||||
## Convert a world position to integer cell coordinates.
|
||||
static func world_to_cell(pos: Vector3) -> Vector2i:
|
||||
return Vector2i(
|
||||
int(floorf(pos.x / CELL_SIZE)),
|
||||
int(floorf(pos.z / CELL_SIZE)),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue