【问题标题】:ROBLOX - Fixing the gaps in hexagon terrainROBLOX - 修复六边形地形的间隙
【发布时间】:2015-10-31 02:27:51
【问题描述】:

所以,我一直在搞乱来自here 的一些高度图代码

在搞砸了参数之后,我改变了六边形的部分,并用它做了一个漂亮的菱形形状,但问题是,六边形边没有相遇的间隙here

这是负责生成的代码,例如:

local size = Vector3.new(10, -- Number of tiles along the width
                         10, -- Number of steps of heightmap
                         10) -- Number of tiles along the length

local base  = script.Parent -- The part to replace with terrain

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)     --Shift the part by half it's size, so we can position the corner
        tile.CFrame = tile.CFrame - base.Size / 2 --Shift it into one corner of the base
        tile.CFrame = tile.CFrame + position      --Put it in the right place
        tile.CFrame = base.CFrame * tile.CFrame   --Move it so that it is level with the surface of the base
        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 -- an end for each for loop

base:Destroy()

【问题讨论】:

  • local position = (Vector3.new(.75, 0, -.5) * (x-1) + Vector3.new(.75, 0, .5) * (z-1)) * tile.Size
  • 你很漂亮。谢谢。
  • 已更新以摆脱菱形组(请参阅已接受的答案)

标签: lua heightmap roblox


【解决方案1】:

我相信解决这个问题的方法是如何设置位置。试试这个:

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

编辑:

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

local size = 10 -- Number of tiles along the side of "big hexagon"

local base  = script.Parent -- The part to replace with terrain

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)     --Shift the part by half it's size, so we can position the corner
        tile.CFrame = tile.CFrame - base.Size / 2 --Shift it into one corner of the base
        tile.CFrame = tile.CFrame + position      --Put it in the right place
        tile.CFrame = base.CFrame * tile.CFrame   --Move it so that it is level with the surface of the base
        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 -- an end for each for loop

base:Destroy()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多