Hey all!
I’m making a game functionally similar to “Project Zomboid” - An isometric zombie survival game, I’ve got the isometric camera figured out but i came across an issue - Roofs.
I’ve thought of ideas to hide to roof (i.e. raycasting) but this 1. Wouldn’t hide everything needed 2. Would have significant performance implications
--LocalScript in StarterPlayerScripts
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = character:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")
local CollectionService = game:GetService("CollectionService")
local RoofTag = "Roof"
RunService.RenderStepped:Connect(function()
if character and character:FindFirstChild("HumanoidRootPart") then
local root = character.HumanoidRootPart
for _, part in pairs(CollectionService:GetTagged(RoofTag)) do
if (camera.CFrame.Position - part.Position).Magnitude < 60 then
part.LocalTransparencyModifier = .8
else
part.LocalTransparencyModifier = 0
end
end
end
end)
Add to the parts you wish to go transparent-ish
Mess around with this number .Magnitude < 60
A bit more refined
LocalScript
--LocalScript in StarterPlayerScripts
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local character = player.Character or player.CharacterAdded:Wait()
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = character:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")
local CollectionService = game:GetService("CollectionService")
local RoofTag = "Roof"
local hiddenRoofs = {}
RunService.RenderStepped:Connect(function()
if not (character and character:FindFirstChild("HumanoidRootPart")) then return end
local root = character.HumanoidRootPart
for _, part in pairs(CollectionService:GetTagged(RoofTag)) do
local distance = (camera.CFrame.Position - part.Position).Magnitude
local shouldHide = distance < 60
if shouldHide and not hiddenRoofs[part] then
part.LocalTransparencyModifier = 0.8
hiddenRoofs[part] = true
elseif not shouldHide and hiddenRoofs[part] then
part.LocalTransparencyModifier = 0
hiddenRoofs[part] = nil
end
end
end)
I really don’t like doing this kind of loop:
RunService.RenderStepped:Connect(function()
Just testing here, it maybe the best choice here.