I’m making procedurally generated terrain for my game, and I was wondering if there’s a way to hide specific faces of Parts to not render? There’s a bunch of individual transparent Water parts and I’d like to hide the faces that aren’t the surface of the water.
Here’s the current code I use to generate these water blocks:
if blockHeight < SEA_LEVEL then
local waterBlock = biomeBlocks.water:Clone()
waterBlock.CFrame = CFrame.new(x * BLOCK_SIZE, SEA_LEVEL, z * BLOCK_SIZE)
-- work in progress - set the size to reach to the lake bottom
-- waterBlock.Size = Vector3.new(waterBlock.Size.X, SEA_LEVEL + 1 - block.Size.Y, waterBlock.Size.Z)
waterBlock.Parent = chunkFolder
end
What solutions have you tried so far?
I’ve tried using Part:UnionAsync() but it ends up being slow and inaccurate with the code I wrote (put below). I’d love feedback if I messed up somewhere.
waterBlocksInChunk = {}
-- in above code block use table.insert(waterBlocksInChunk, waterBlock)
if #waterBlocksInChunk ~= 0 then
print(waterBlocksInChunk)
local part = table.remove(waterBlocksInChunk, 1)
local success, unionedWater: UnionOperation = pcall(function()
return part:UnionAsync(waterBlocksInChunk)
end)
if success and unionedWater then
unionedWater.Position = part.Position
unionedWater.Parent = chunkFolder
part:Destroy()
for _, block in pairs(waterBlocksInChunk) do
block:Destroy()
end
else
print(unionedWater) -- debug
end
end
It would be much simpler to just hide every face of the Part that isn’t the top face in order to prevent the texture clashing.
You can’t edit or unrender certain faces of polygon in a Basepart (basically engine limitation).
I suggest you make a custom mesh that only has a top polygon or make the part very thin.
If your water only appears at a certain height then get an infinite water mesh then set it on that height.
Thanks for the help, with your suggestion I solved my problem with an alternative method:
-- above: generate terrain
local waterBlock = biomeBlocks.water:Clone()
-- Subtract 2 to offset it from being directly on the beach line
waterBlock.CFrame = CFrame.new(0, SEA_LEVEL - 2, 0)
waterBlock.Size = Vector3.new(50000, SEA_LEVEL, 50000)
waterBlock.Parent = workspace
You’ll have to use a mesh like @vipkute0057 mentioned, however I do believe that you can use the new EditableMesh API in order to edit meshes with code. This would allow you to dynamically control which faces exist. Though I don’t think editing a mesh will change its collision. It should also be noted that this API is only in Studio Beta and therefore won’t work in live servers yet.
The only reason I’d recommend not using this is if the experience in question has caves, in which obviously you wouldn’t want water flooding them (unless you do), but it’s probably the best option otherwise.
It’s not exactly related, but I’d also recommend looking into EditableImage as both APIs released at the same time and are both still in Studio Beta.