diff --git a/src/dusk/rpg/rpgcamera.c b/src/dusk/rpg/rpgcamera.c index 89058643..b64ac9b0 100644 --- a/src/dusk/rpg/rpgcamera.c +++ b/src/dusk/rpg/rpgcamera.c @@ -45,14 +45,17 @@ errorret_t rpgCameraUpdate(void) { vec3 pos; rpgCameraGetPosition(pos); - worldpos_t worldPos = { - (worldunit_t)pos[0], - (worldunit_t)pos[1], - (worldunit_t)pos[2] + + // Round to the nearest chunk center rather than flooring, so the + // loaded window is always most centered on what the camera sees. + // Adding half the chunk dimension before flooring snaps at the + // midpoint of each chunk instead of at the boundary. + chunkpos_t chunkPos = { + .x = (chunkunit_t)floorf(pos[0] / CHUNK_WIDTH + 0.5f), + .y = (chunkunit_t)floorf(pos[1] / CHUNK_HEIGHT + 0.5f), + .z = (chunkunit_t)floorf(pos[2] / CHUNK_DEPTH + 0.5f) }; - chunkpos_t chunkPos; - worldPosToChunkPos(&worldPos, &chunkPos); - + errorChain(mapPositionSet((chunkpos_t){ .x = chunkPos.x - (MAP_CHUNK_WIDTH / 2), .y = chunkPos.y - (MAP_CHUNK_HEIGHT / 2),