#How to get Chunks
1 messages · Page 1 of 1 (latest)
Just divide by 16?
divide what exactly?
0,0,0 position?
The world coordinates.
But that alone doesn't guarantee that it's the center of a chunk, does it?
It's simple math, each chunk is 16x16 on the x/z axis. Get a random coordinate, and calcukate the nearest chunk border.
Do math.
const chunkX = Math.floor(pos.x / 16);
const chunkZ = Math.floor(pos.z / 16);
const cornerX = chunkX * 16;
const cornerZ = chunkZ * 16;```
this should work, right?
const { x: locX, y: locY, z: locZ } = player.location;
const chunkIndex = {
x: Math.floor(locX / 16),
y: Math.floor(locY / 16),
z: Math.floor(locZ / 16)
};
const relativePosition = {
x: Math.floor(locX % 16),
y: Math.floor(locY % 16),
z: Math.floor(locZ % 16)
};```
I had this code
just shared it if you need
thank you!
but I will use this since I have to get the chunk corner to place a structure
and Yes your math is right for getting the corner
thx