Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the best way to get adjacent terrain cells?

I have looked through the terrain API and haven't found anything that helps get you adjacent terrain cells. I'm also not certain if terrain has its own coordinate system or what the distance between two adjacent pieces of terrain is. Is there a recommended way of getting adjacent cells?

1 answer

✓ Accepted answer

Terrain has his own coordinate system. This will set the cell where you click and the adjacent sells to asphalt.

mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:connect(function()
	local cellpos = Workspace.Terrain:WorldToCell(mouse.Hit.p) --Get the cell position in terrain coordiante
	if cellpos then
		for x = cellpos.x - 1, cellpos.x + 1 do
			for z = cellpos.z - 1, cellpos.z + 1 do 
				Workspace.Terrain:SetCell(x, cellpos.y-1, z, 5, 0, 1) --Set cells
			end
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.