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

Using CopyRegion and PasteRegion to load chunks of terrain?

Asked by 7 years ago
Edited 7 years ago

I've recently been wanting to create maps using terrain that I can save, remove, and then load later, but it isn't working out for me so far. No errors occur, but no terrain appears. The wiki offers no tutorials that don't use workspace.Terrain.Max/MinExtents so it's hard to understand why this isn't working.

Terrain

CopyRegion

PasteRegion

Here's my code:

local region = workspace.Terrain:CopyRegion(Region3int16.new(Vector3int16.new(-103, 0.5, 13.2), Vector3int16.new(-27.4, 42.4, 87.6)))
workspace.Terrain:Clear()
workspace.Terrain:PasteRegion(region, Vector3int16.new(-103, 0.5, 13.2), false)

1 answer

Log in to vote
0
Answered by 7 years ago

For anyone who is having the same problem, you must round your positions to Roblox's voxel size.

Here's what I got right after I pulled the positionToWorldVoxel right out of the Roblox Studio Terrain Tools

local ceil          = math.ceil
local resolution    = 4

local function positionWorldToVoxel(pos)
    return Vector3int16.new(ceil(pos.x / resolution), ceil(pos.y / resolution), ceil(pos.z / resolution))
end

local region = workspace.Terrain:CopyRegion(Region3int16.new(
        positionWorldToVoxel(Vector3.new(-103, 0.5, 13.2)),
        positionWorldToVoxel(Vector3.new(-27.4, 42.4, 87.6))
    )
)

workspace.Terrain:Clear()
wait(1)
workspace.Terrain:PasteRegion(region, positionWorldToVoxel(Vector3.new(-103, 0.5, 13.2)), false)

1
dude i love your plugin to load characters speedyfox66 237 — 5y
Ad

Answer this question