This is a function that moves terrain by reading the voxels and moving them making for an interesting and unique effect you can use to create moving terrain platforms. Important thing to note is I think this only works on an already occupied region of terrain. It still does it thing even while the region is empty. If you want to create a region place terrain:FillBlock(CFrame.new(start),Vector3.new(40,40,40),Enum.Material.Basalt)
-- A script that uses the terrain API to create a moving terrain section modified by a size variable
-- Define the size variable
local size = 40 -- change this to any value you want
-- Get the terrain object
local terrain = workspace.Terrain
local start=Vector3.new(20, -20, 20)
-- Create a region to select a section of terrain
local region = Region3.new(start- Vector3.new(size/2, size/2, size/2),start+ Vector3.new(size/2, size/2, size/2))
--local endpoint=Vector3
-- Get the terrain material and occupancy data from the region
local curpos=start
local endpos=Vector3.new(100,20,0)
-- Define a function to move the terrain section by a given offset
local function moveTerrain(offset)
-- Create a new region with the offset applied
local newRegion = Region3.new(region.CFrame.Position + offset- Vector3.new(size/2, size/2, size/2), region.CFrame.Position + Vector3.new(size/2, size/2, size/2) + offset)
-- local newRegion = Region3int16.new(Vector3int16.new(region.CFrame.Position + offset), Vector3int16.new(region.CFrame.Position + Vector3.new(size, size, size) + offset))
-- Write the material and occupancy data to the new region
if occupancy~=nil then
terrain:FillRegion(region, 4, Enum.Material.Air)
terrain:WriteVoxels(newRegion, 4, material, occupancy)
-- Clear the original region
-- Update the region variable to the new region
region = newRegion
end
return region.CFrame.Position
end
--terrain:FillRegion(region, 4, Enum.Material.Grass)
wait()
--Read Occupany after filling region. Do not fill region if region already occupied. Do not read empty voxels returns error
material, occupancy = terrain:ReadVoxels(region, 4)
-- Define a loop to move the terrain section repeatedly
while true do
-- Move the terrain section by 4 studs in the x direction
if curpos.X>=endpos.X then
mult=-1
elseif curpos.X<=start.X then
mult=1
end
curpos=moveTerrain(Vector3.new(2*mult, 0, 0))
task.wait(.1)
end