How would I have chunks generate in a square extending 150 studs from the HumanoidRootPart?

The title is basically the whole thread…

I can’t find anything on this, and I have no idea how to do it.

And apparently no one else does, or it seems like it.

1 Like

You don’t explain much about how you want chunks to be processed- but really all you need is a function that takes a Vector3 input and can output what chunk it exists in (this way you can call this function to determine if a chunk is viable or not. I’ve always used modulus for this.

This function can be wrote like so:

local C_SIZE = 5 -- Chunk size (5 = 5x5)

local function getChunkByVector(Vector)
	local X, Z = math.floor(Vector.X), math.floor(Vector.Z)
	local X_Iteration, Z_Iteration = 0, 0
	local X_Final, Z_Final = false, false
	
	repeat X -= 1 X_Iteration += 1 until (X%C_SIZE) == 0 or X_Iteration > C_SIZE
	repeat Z -= 1 Z_Iteration += 1 until (Z%C_SIZE) == 0 or Z_Iteration > C_SIZE
	
	X_Final = if X_Iteration <= C_SIZE then X else false
	Z_Final = if Z_Iteration <= C_SIZE then Z else false

	if X_Final and Z_Final then
		return X_Final, Z_Final
	else
		warn("Function timed out...")
	end
end

You can then do whatever you like to with your system. Use what it returns to construct and evaluate the magnitude between that chunk’s location and the HumanoidRootPart. If the resulting magnitude is less than 150, then you know the chunk exists in your grid.

If you’re using this for a placement system you can cache which chunks are in use and what objects exist inside of them.