From d14aa149918f3f8e4437d4e8b65c13a2b06d212d Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Thu, 03 Apr 2025 21:12:13 +0000
Subject: [PATCH] #42 fix chunk y position
---
Assets/Scripts/GenerateTileMap.cs | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/Assets/Scripts/GenerateTileMap.cs b/Assets/Scripts/GenerateTileMap.cs
index 7bf0667..d74153b 100644
--- a/Assets/Scripts/GenerateTileMap.cs
+++ b/Assets/Scripts/GenerateTileMap.cs
@@ -124,7 +124,7 @@
private void UnloadChunk(Vector2Int chunk)
{
int startX = chunk.x * CHUNK_SIZE;
- int startY = chunk.y * CHUNK_SIZE;
+ int startY = (chunk.y * CHUNK_SIZE)-1;
for (int x = startX; x < startX + CHUNK_SIZE; x++)
{
@@ -207,7 +207,7 @@
{
// Adjust for tilemap offset
float adjustedX = worldPosition.x - transform.position.x;
- float adjustedY = worldPosition.y - transform.position.y;
+ float adjustedY = (worldPosition.y - transform.position.y) + CHUNK_SIZE;
return new Vector2Int(
Mathf.FloorToInt(adjustedX / CHUNK_SIZE),
@@ -232,7 +232,7 @@
private IEnumerator GenerateChunk(Vector2Int chunk, List<Vector3Int> destroyedTiles)
{
int startX = chunk.x * CHUNK_SIZE;
- int startY = (chunk.y * CHUNK_SIZE);
+ int startY = (chunk.y * CHUNK_SIZE)-1;
// Generate ground in chunk
for (int x = startX; x < startX + CHUNK_SIZE; x++)
@@ -473,10 +473,17 @@
0
);
+ // Draw chunk boundary
Gizmos.DrawWireCube(
worldPos + new Vector3(CHUNK_SIZE / 2f, -CHUNK_SIZE / 2f, 0),
new Vector3(CHUNK_SIZE, CHUNK_SIZE, 0)
);
+
+ // Draw chunk coordinates
+ UnityEditor.Handles.Label(
+ worldPos + new Vector3(CHUNK_SIZE / 2f, -CHUNK_SIZE / 2f, 0),
+ $"({chunk.x}, {chunk.y})"
+ );
}
}
}
--
Gitblit v1.10.0