Issues with a terrain generation system that uses Hexagons

one spot, as if they are sometimes z-clipping?

1 Like

There is none. I believe this is why: It adds offset, but without it, the meshes would z-clip (Line 78 z *= 3.732 * 0.25)

1 Like

so explain to me, because i dont understand what is the issue now?

1 Like

I’m sorry that the problem is difficult. But, my issue now is placing the hexagons like the image below:

1 Like

can you send the place file now?

1 Like

current.rbxl (59.7 KB)
Here’s the game file

1 Like

obraz
is this what you want?

2 Likes

Yes, but the rotation is off by 45 degrees (my part).

1 Like

you mean the thing in my image? i just stood in a weird way, its rotated normally

1 Like

No the hexagons. (my bad; I’m getting there with my explanation of things)

1 Like

ok, if you think you can handle the rest because i dont really understand what you mean, change the

if z % 2 == 0 then
    z += 3.732 * 0.5
else
    z += 3.732 * 0.25 --or maybe 0.75?
end

with

z += 3.732 * .5
1 Like

Okay, Thanks! It gives stripes still.

1 Like

thats weird, i simply change that to this and it doesnt give me stripes

1 Like

It is happening on the z-axis. I don’t know what I’m doing wrong.

1 Like

can you show the script? [30 сhars]

1 Like
local FractalNoise = require(game.ServerStorage.FractalNoise)
local heightmapNoise = FractalNoise(nil, 0.1, 2, 2, nil, nil) --These are just magic numbers
local swirlNoise = FractalNoise(nil, .01, 5, 2) --These are just magic numbers

function mapSet(map, x, y, z, value)
	map[x] = map[x] or {}
	map[x][y] = map[x][y] or {}
	map[x][y][z] = value
end

function mapGet(map, x, y, z)
	if map[x] then
		if map[x][y] then
			return map[x][y][z]
		end
	end
end

function twirlCoordinates(x, y, z, power)
	local power = power or 1
	local tX, tY, tZ = 	
		swirlNoise(x, y, z),
		swirlNoise(x+1000, y, z), --Don't want the *same* twirl on each axis
		swirlNoise(x, y+1000, z)

	return x + tX * power, y + tY * power, z + tZ * power
end

function heightMap(x, z)
	return heightmapNoise(x, 0, z)
end

function density(x, y, z)
	--If you twirl with power 0, you'll just get a plain heightmap
	local tX, tY, tZ = twirlCoordinates(x, y, z, 1)
	tZ = tZ / (1 + y)
	tX = tX / (1 + y)
	local densityOffset = 0.5 + heightMap(tX, tZ) - y --Add 0.5 density so that there's a guaranteed bottom layer
	return densityOffset
end

function generateChunk(mapSize, offset)
	local yMax = 25
	local yMin = 1
	print(offset)

	local x
	local y
	local z

	local densityMap = {}
	for x = 1, mapSize do
		for y = yMin, yMax do
			for z = 1, mapSize do
				mapSet(densityMap, x*offset["x"], y, z*offset["z"], density((x*offset["x"])/mapSize, y/(yMax), (z*offset["z"])/mapSize))
			end
		end
	end

	x, y, z = 0,0,0

	for x = 1, mapSize do
		for y = yMin, yMax do
			for z = 1, mapSize do
				local d = mapGet(densityMap, x*offset["x"], y, z*offset["z"]) 
				--print(d, x*offset["x"], y, z*offset["z"])

				if d >= 0 and d <= 0.14 then
					local block = workspace.blockBase.Base_Plane:Clone()
					--local block = Instance.new("Part", workspace)
					--block.Size = Vector3.new(4, 4, 4)
					
					z *= 3.732 * 0.5

					block.Anchored = true
					block.CFrame = CFrame.new((x*offset["x"])*4, y*4, (z*offset["z"])*3.732) -- this is the positioning
					block.Color = Color3.fromHSV(((y/mapSize)%1), .75, 1 - (y/mapSize))
					block.Parent = game.Workspace
				end

			end

		end
		game["Run Service"].Heartbeat:Wait()
	end
	x, y, z = 0,0,0
end


generateChunk(16, {
	["x"] = 1,
	["z"] = 1
})
1 Like

yeah, you put *=, you need to put += (z += 3.732 * .5)
multiplication sign and plus sign have a huge difference as you notice here

1 Like

That helps, but the offsets need to be like a tile grid (that is why I had code for the x-axis)

1 Like

aren’t they like a tile grid already?

1 Like

Not really. Look at the difference between the image you sent me and the one I used as reference to what I want with details (excluding rotation).

1 Like