ROBLOX - 修复六边形地形中的空隙

所以,我一直在折磨着来自这里的一些地形图代码

在玩弄参数后,我改变了六边形形状的一部分,并用它制作了一个漂亮的类似于钻石的形状,但问题是,在六边形边不连接的地方有间隙,如此显示

下面是负责生成代码等的代码:

local size = Vector3.new(10, -- width的数量
                         10, -- heightmap的步数
                         10) -- length的数量

local base = script.Parent -- 要替换为地形的部分

math.randomseed(tick() % 1e5)

for x = 1, size.x do
    for z = 1, size.z do
        local y = x + z
        wait()
        local tile = game.ServerStorage.Hexagon:Clone()

        local position = Vector3.new(x-1, 0, z-1) * tile.Size
        tile.Size = tile.Size * Vector3.new(1, y, 1)
        tile.CFrame = CFrame.new(tile.Size/2)     --平移部分一半的大小,以便我们可以定位角落
        tile.CFrame = tile.CFrame - base.Size / 2 --将其移动到基底的一个角落
        tile.CFrame = tile.CFrame + position      --将其放在正确的位置上
        tile.CFrame = base.CFrame * tile.CFrame   --将它移动,使它与基底表面平齐
        tile.Parent = workspace

        if tile.Position.Y < 30 then
            tile.BrickColor = BrickColor.new("Brown")
        elseif tile.Position.Y > 30 and tile.Position.Y < 100 then
            tile.BrickColor = BrickColor.new("Bright green")
        end
    end
end --每个循环的结尾

base:Destroy()
点赞
用户3979429
用户3979429

我认为这个问题的解决方案在于如何设置位置。试试这个:

local position = (Vector3.new(.75, 0, -.5)*(x-1) + Vector3.new(.75, 0, .5)*(z-1))*tile.Size

编辑:

完整的代码(它还将瓷砖组成“大六边形”而不是“大菱形”):

local size = 10 -- 大六边形沿边有多少个瓷砖

local base  = script.Parent -- 要替换地形的部件

math.randomseed(tick()%1e5)

for x = 0, 2*size do
    for z = 0, 2*size do
        if ((x + z)/size - 2)^2 > 1 then break end
        local y = x+z
        wait()
        local tile = game.ServerStorage.Hexagon:Clone()

        local position = Vector3.new(.75*(x+z), 0, .5*(z-x)) * tile.Size
        tile.Size = tile.Size * Vector3.new(1, y, 1)
        tile.CFrame = CFrame.new(tile.Size/2)     --移动部分大小的一半,以便我们可以定位角落
        tile.CFrame = tile.CFrame - base.Size / 2 --将其移到底座的一个角落
        tile.CFrame = tile.CFrame + position      --放在正确的位置上
        tile.CFrame = base.CFrame * tile.CFrame   --将其移动到与底座的表面平齐的位置
        tile.Parent=workspace

        if tile.Position.Y < 30 then
            tile.BrickColor = BrickColor.new("Brown")
        elseif tile.Position.Y > 30 and tile.Position.Y < 100 then
            tile.BrickColor = BrickColor.new("Bright green")
        end
    end
end -- 由于每个for循环都有一个结束符号

base:Destroy()
2015-10-29 23:27:53