Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the best way to get adjacent terrain cells?

Asked by 9 years ago

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

Log in to vote
0
Answered by
Destrings 406 Moderation Voter
9 years ago

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)
Ad

Answer this question