Should I clone the scenery or use viewports?

Include a standalone, bare-bones rbxl file with only the code you want reviewed.
Backrooms.rbxl (33.0 KB)

Provide an overview of:
The WrapAround script found in StarterPlayer.StarterCharacterScripts checks if the player is eitther under -128 or over 128 in the x and z axes and subtracts or adds 256 to their position to warp them from the other side, but if you run the game, that is not noticeable, here’s why:

The map is generated, then cloned in 8 directions, you can never access these extra maps, they’re just there to make the wrap around look seamless.

I wanted an opinion on wether using viewports would be better or worse off performance wise, both with the current map size and a considerably bigger, more complex one.

For the wrap around, I was checking the player’s position every renderstep, I could try using the touched event even though i don’t think it would be nearly as seamless.

These changes would be performance focused, so I wanted to get a second opinion before working on them, maybe get some other suggestions

Wrap around script:

local rs = game:GetService("RunService")
local h = script.Parent.HumanoidRootPart
script.Parent:SetPrimaryPartCFrame(CFrame.new(0,8,0))

local function WrapAround()
	if h.Position.Magnitude < 127 then return end
	
	if h.Position.X > 128 then 
		h.CFrame -= Vector3.new(256,0,0)
	elseif 
		h.Position.X < -128 then 
		h.CFrame += Vector3.new(256,0,0)
	end

	if h.Position.Z > 128 then 
		h.CFrame -= Vector3.new(0,0,256)
	elseif h.Position.Z < -128 then 
		h.CFrame += Vector3.new(0,0,256)
	end
end

rs:BindToRenderStep("WrapAround" , 50 , WrapAround)

Tile generator script:

local x = -120
local z = -120
local obj = game.ReplicatedStorage.OneWall
local c

for i = 1,16 do
	for i = 1,16 do
		c = obj:Clone()
		c.Parent = workspace.Center
		c:SetPrimaryPartCFrame(CFrame.new(x , 0.5 , z))
		c.Randomize:Invoke()
		x += 16
	end
	z += 16
	x = -120
end

for i , v in pairs(workspace.Center:GetChildren()) do
	c = v:Clone()
	c.Parent = workspace.Up
	c.PrimaryPart.CFrame += Vector3.new(0,0,256)
end

for i , v in pairs(workspace.Center:GetChildren()) do
	c = v:Clone()
	c.Parent = workspace.UpRight
	c.PrimaryPart.CFrame += Vector3.new(256,0,256)
end

for i , v in pairs(workspace.Center:GetChildren()) do
	c = v:Clone()
	c.Parent = workspace.UpLeft
	c.PrimaryPart.CFrame += Vector3.new(-256,0,256)
end


for i , v in pairs(workspace.Center:GetChildren()) do
	c = v:Clone()
	c.Parent = workspace.Down
	c.PrimaryPart.CFrame += Vector3.new(0,0,-256)
end

for i , v in pairs(workspace.Center:GetChildren()) do
	c = v:Clone()
	c.Parent = workspace.DownRight
	c.PrimaryPart.CFrame += Vector3.new(256,0,-256)
end

for i , v in pairs(workspace.Center:GetChildren()) do
	c = v:Clone()
	c.Parent = workspace.DownLeft
	c.PrimaryPart.CFrame += Vector3.new(-256,0,-256)
end

for i , v in pairs(workspace.Center:GetChildren()) do
	c = v:Clone()
	c.Parent = workspace.Right
	c.PrimaryPart.CFrame += Vector3.new(256,0,0)
end

for i , v in pairs(workspace.Center:GetChildren()) do
	c = v:Clone()
	c.Parent = workspace.Left
	c.PrimaryPart.CFrame += Vector3.new(-256,0,0)
end

considering you have a one time creation cost (you arn’t creating and destroying walls)
It would be best to copy everything over to the viewport for whatever you want to use it for

1 Like

Viewports are wayyy more optimized, it costs a couple pixels but saves your performance big time.