I finally figured it out! yay. It seems not a lot of developers use terrain all that often so…
My problem with why only -32000 worked, was because with the copy region function we use workspace.Terrain.MaxExtents
, which returns -32000, -32000, -32000; 32000, 32000, 32000.
It uses those 2 corners, and the lower one is the -32000. The “corner” in the terrain paste function is the point where you want the lower exten of the copied region to end up. So the lower corner of the terrain will end at the corner value. This makes sence, why -32000 for the corner value would only work, because thats where the terrain was previous. I cant explain it that well but look at this code.
local terrainRegion = workspace.Terrain:CopyRegion(Region3int16.new(Vector3int16.new(-32000, -32000, -32000) , Vector3int16.new(32000, 32000, 32000)))
workspace.Terrain:Clear()
wait(5)
local corner = Vector3int16.new(-32000, -32000, -32000)
local pasteEmptyRegion = false
workspace.Terrain:PasteRegion(terrainRegion, corner, pasteEmptyRegion)
Yea, so as you can see, its like copying a area, when pasting back in that area. It might be ok to use workspace.Terrain.MaxExtents
if you want to copy a terrain map or something, but I would just get the region of the terrain you want to copy.
What I found is indeed everything is in voxel coordinates(4’s), with copy and paste functions.
Here is a bit of code that might prove useful for anyone.
This just takes a normal Vector3 position and copys a selected area, and paste it at a second position, both in “normal” coordinates.
local ArenaSize = Vector3.new(100, 100, 100) -- normal cordnates
local function onSetArenaPosition(Player, vector, finalpos) -- normal cordnates
if typeof(vector) == "Vector3" and typeof(finalpos) == "Vector3" then
local min = (vector - ArenaSize/2)
local max = (vector + ArenaSize/2)
local minVoxels = Vector3int16.new(
math.floor(min.x/4),
math.floor(min.y/4),
math.floor(min.z/4))
local maxVoxels = Vector3int16.new(
math.floor(max.x/4),
math.floor(max.y/4),
math.floor(max.z/4))
local region = Region3int16.new(minVoxels,maxVoxels)
local terrainRegion = workspace.Terrain:CopyRegion(region)
local corner = Vector3int16.new(
math.floor(finalpos.y/4),
math.floor(finalpos.x/4),
math.floor(finalpos.z/4))
workspace.Terrain:PasteRegion(terrainRegion, corner, true)
else
warn("not a valid value")
return
end
end
Im working on a module for terrain loading and stuff for games with big terrain maps, and to help a lot with lag too.