Roblox 柏林噪声孔

问题描述

好的,所以我一直在 roblox (lua) 上编写游戏脚本,并且主要地形生成脚本正在运行,在我的地形中留下了大量死角。 Me standing at edge of "infinite" terrain

这是来自 roblox devforum 的修改代码,我首先检查了答案。

local Players = game:GetService("Players")
local chestcount = 0

------------------------------------------------------------------------------------------------------------------------------------------------

local BASE_HEIGHT       = 10                -- The main height factor for the terrain.
local CHUNK_SCALE       = 3             -- The grid scale for terrain generation. Should be kept relatively low if used in real-time.
local RENDER_disTANCE   = 500 / 4           -- The length/width of chunks in voxels that should be around the player at all times
local X_SCALE           = 150 / 4       -- How much we should strech the X scale of the generation noise
local Z_SCALE           = 150 / 4           -- How much we should strech the Z scale of the generation noise
local GENERATION_SEED   = math.random()     -- Seed for determining the main height map of the terrain.

------------------------------------------------------------------------------------------------------------------------------------------------

local chunks = {}

local function mountLayer(x,heightY,z,material)
    local genchest = math.random(1,10000)
    local beginY = -BASE_HEIGHT
    local endY = heightY
    
    local cframe = CFrame.new(x * 4 + 2,(beginY + endY) * 4 / 2,z * 4 + 2)
    local size = Vector3.new(4,(endY - beginY) * 4,4)
    
    workspace.Terrain:FillBlock(cframe,size,material)

    if genchest == 1 then

        chestcount = chestcount + 1

        local chest = game.ReplicatedStorage.Chest:Clone()
        chest:SetPrimaryPartCFrame(cframe)
        chest:SetPrimaryPartCFrame(CFrame.new(chest.PrimaryPart.Position.X,chest.PrimaryPart.Position.Y + (size.Y / 2) + 3,chest.PrimaryPart.Position.Z))
        chest.Name = "chest " .. chestcount
        chest.Parent = workspace
        
    end
    
end

local function chunkExists(chunkX,chunkZ)
    if not chunks[chunkX] then
        chunks[chunkX] = {}
    end
    return chunks[chunkX][chunkZ]
end



function makeChunk(chunkX,chunkZ)
    local rootPosition = Vector3.new(chunkX * CHUNK_SCALE,chunkZ * CHUNK_SCALE)
    chunks[chunkX][chunkZ] = true -- AckNowledge the chunk's existance.
    for x = 0,CHUNK_SCALE - 1 do
        for z = 0,CHUNK_SCALE - 1 do
            local cx = (chunkX * CHUNK_SCALE) + x
            local cz = (chunkZ * CHUNK_SCALE) + z
            local noise = math.noise(GENERATION_SEED,cx / X_SCALE,cz / Z_SCALE)
            local cy = noise * BASE_HEIGHT
            mountLayer(cx,cy,cz,Enum.Material.Ice)
        end
    end
end

function checkSurroundings(location)
    local chunkX,chunkZ = math.floor(location.X / 3 / CHUNK_SCALE),math.floor(location.Z / 3 / CHUNK_SCALE)
    local range = math.max(1,RENDER_disTANCE / CHUNK_SCALE)
    for x = -range,range do
        for z = -range,range do
            local cx,cz = chunkX + x
            local cz = chunkZ + z
            if not chunkExists(cx,cz) then
                makeChunk(cx,cz)
            end
        end
    end
end

while true do
    for _,player in pairs(Players:GetPlayers()) do
        if player.Character then
            local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
            if humanoidRootPart then
                checkSurroundings(humanoidRootPart.Position)
            end
        end
    end
    wait(1)
end     

代码在您创建大片土地之前似乎一直有效,通常会导致生成“L”形,在该处不会生成内角。我知道这里没有很多 roblox 帖子,但这几乎是我能想到的唯一地方。该脚本使用 perlin 噪声贴图在“玩家”周围生成地形,所以我想知道我使用的算法是否有问题,或者我是否只是设置了一些错误。告诉我,谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)