Fix tile grid alignment issues

This commit is contained in:
kayomn 2023-01-31 22:29:30 +00:00
parent 176b18866f
commit 647ac60ce7
2 changed files with 12 additions and 6 deletions

BIN
map_editor.scn (Stored with Git LFS)

Binary file not shown.

View File

@ -62,9 +62,9 @@ class Chunk:
transforms_by_mesh[mesh].append(Transform3D( transforms_by_mesh[mesh].append(Transform3D(
Basis.IDENTITY.rotated(Vector3.UP, half_pi * _floor_orientation[i]), Vector3( Basis.IDENTITY.rotated(Vector3.UP, half_pi * _floor_orientation[i]), Vector3(
(float(coordinate.x * _CHUNK_SIZE) + (i % _CHUNK_SIZE)) - (float(coordinate.x * _CHUNK_SIZE) + (i % _CHUNK_SIZE)) -
(float(grid_size.x) * _GRID_ORIGIN.x), 0.0, (float(grid_size.x) * _GRID_ORIGIN.x) + 0.5, 0.0,
(float(coordinate.y * _CHUNK_SIZE) + (i / _CHUNK_SIZE)) - (float(coordinate.y * _CHUNK_SIZE) + (i / _CHUNK_SIZE)) -
(float(grid_size.y) * _GRID_ORIGIN.y)))) (float(grid_size.y) * _GRID_ORIGIN.y) + 0.5)))
for i in _wall_meshes.size(): for i in _wall_meshes.size():
var mesh := _wall_meshes[i] var mesh := _wall_meshes[i]
@ -76,9 +76,9 @@ class Chunk:
transforms_by_mesh[mesh].append(Transform3D( transforms_by_mesh[mesh].append(Transform3D(
Basis.IDENTITY.rotated(Vector3.UP, half_pi * _wall_orientation[i]), Vector3( Basis.IDENTITY.rotated(Vector3.UP, half_pi * _wall_orientation[i]), Vector3(
(float(coordinate.x * _CHUNK_SIZE) + (i % _CHUNK_SIZE)) - (float(coordinate.x * _CHUNK_SIZE) + (i % _CHUNK_SIZE)) -
(float(grid_size.x) * _GRID_ORIGIN.x), 0.0, (float(grid_size.x) * _GRID_ORIGIN.x) + 0.5, 0.0,
(float(coordinate.y * _CHUNK_SIZE) + (i / _CHUNK_SIZE)) - (float(coordinate.y * _CHUNK_SIZE) + (i / _CHUNK_SIZE)) -
(float(grid_size.y) * _GRID_ORIGIN.y)))) (float(grid_size.y) * _GRID_ORIGIN.y) + 0.5)))
# (Re)-bake into multimesh instances for the chunk. # (Re)-bake into multimesh instances for the chunk.
var scenario_rid := tile_grid.get_world_3d().scenario var scenario_rid := tile_grid.get_world_3d().scenario
@ -324,3 +324,9 @@ func plot_tile(coordinates: Vector2i, orientation: Orientation, tile: Tile) -> v
Tile.Kind.WALL: Tile.Kind.WALL:
chunk.set_wall_mesh(coordinates % _CHUNK_SIZE, orientation, mesh) chunk.set_wall_mesh(coordinates % _CHUNK_SIZE, orientation, mesh)
chunk.invalidate(self, chunk_coordinates) chunk.invalidate(self, chunk_coordinates)
##
##
##
func world_to_grid(world_position: Vector2) -> Vector2i:
return Vector2i((world_position + (Vector2(size) * _GRID_ORIGIN)).round())