diff --git a/map_editor.scn b/map_editor.scn index 2cca5f0..8c0b516 100644 --- a/map_editor.scn +++ b/map_editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:50a5242649107880385206657657a9e77a285eef6a1c683e22210646cd97b7de -size 12700 +oid sha256:144f8810b56cc89b593e8a78fbef8e4970bc82c1dbcd49b636a98a7e51af4464 +size 13347 diff --git a/tiling/tile_grid.gd b/tiling/tile_grid.gd index b591939..fbd2d63 100644 --- a/tiling/tile_grid.gd +++ b/tiling/tile_grid.gd @@ -62,9 +62,9 @@ class Chunk: transforms_by_mesh[mesh].append(Transform3D( Basis.IDENTITY.rotated(Vector3.UP, half_pi * _floor_orientation[i]), Vector3( (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(grid_size.y) * _GRID_ORIGIN.y)))) + (float(grid_size.y) * _GRID_ORIGIN.y) + 0.5))) for i in _wall_meshes.size(): var mesh := _wall_meshes[i] @@ -76,9 +76,9 @@ class Chunk: transforms_by_mesh[mesh].append(Transform3D( Basis.IDENTITY.rotated(Vector3.UP, half_pi * _wall_orientation[i]), Vector3( (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(grid_size.y) * _GRID_ORIGIN.y)))) + (float(grid_size.y) * _GRID_ORIGIN.y) + 0.5))) # (Re)-bake into multimesh instances for the chunk. 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: chunk.set_wall_mesh(coordinates % _CHUNK_SIZE, orientation, mesh) chunk.invalidate(self, chunk_coordinates) + +## +## +## +func world_to_grid(world_position: Vector2) -> Vector2i: + return Vector2i((world_position + (Vector2(size) * _GRID_ORIGIN)).round())