I am trying to make a block placement system for a project. I’ve made some headway but the main issue is that I can’t figure out how to stop the player from having floating blocks without foundation in the game.
When a block is removed by the player, the blocks near the removed one should update and check whether they are still attached to the baseplate, whether that be through being directly connected to the floor, or if their neighbours are attached to the floor already.
I originally tried to run for loops on each of the adjacent blocks to check whether they had support but I ended up with stack overflow.
Any help and ideas on how to go about this would be appreciated!
You make sure all the blocks you place are not Anchored. Then when you place a block you weld it to all adjacent blocks and the ground (the ground is Anchored). Then you loop through all blocks and check if they are grounded, if they are not you break the welds.
Example:
local blocks = {}
local function placeBlock(block, position)
table.insert(blocks, block)
block.Position = position
local adjacentBlocks = workspace:GetPartBoundsInBox(block.CFrame, block.Size)
-- Weld to all adjacent blocks + ground
for _, adjacent in adjacentBlocks do
local weld = Instance.new("WeldConstraint",block)
weld.Part0 = block
weld.Part1 = adjacent
end
-- Each time a block is placed check if all blocks are grounded
-- If they are not, break the welds
for _, block in blocks do
if not block:IsGrounded() then
block:BreakJoints()
end
end
end
placeBlock(workspace.Part)
Physics based is generally very buggy. Physics collisions can introduce weird edge cases and bugs. This might be ok for something where you dont have a grid system (like RUST). However I think OP is asking for a grid-based system. This is preferred esp for server validation and checks.
Other alternatives is to raycast but if grid-based you would use coordinates.
In this case implementing the system is as follows:
determine your grid size ie 1 x 1 studs
server will initialize a data model grid/checkerboard of bools = false.
in build mode lock placements to one grid size. This is done by doing a raycast check and determining the location then doing math rounds to get grid position across your map
when you build send an event to the server and the server will recieved the coordinates and validate against its grid. Use an adjacency algorithm to check neighboring grids and return fail if any of those are already occupied. When it passes set the values to true in your grid and notify the client
If you want the client to render your object red and green if valid then you can do a hybrid solution:
2 options:
client maintains its own copy of the grid and updates accordingly when server responds. (for ex. locally check grid on client side, if passes then notify server xyz coordinates and size of the block ie 2x1x1) then server validates and updates its grid data then responds to client so client can update its data model of the grid data
or client does raycasts or collisions checks as described by the person above (if check passes then you send event to server)
This is completely false. Especially if he is using a rigid grid system where blocks will not be overlapping.
Either way he wants parts to fall which means he wants physics. There is no point in writing your own physics engine when Roblox’s works perfectly fine, especially in a situation like this which it is designed for.
its like chain u weld the block to the block that holding it in place, and that block is might be welded to the block that welded to baseplate or something that anchored and represent ground. if AssemblyRootPart isn’t that baseplate then this means this block is welded to something that aren’t even attached to ground, by using this knowledge we can remove the weld and now whole chain is broken making all blocks fall.
If they are overlapping this is true. He never mentioned whether the blocks would overlap or not. If they did your system will run into weird edge cases. Besides you dont have server validation, which is why I mentioned the hybrid solution
Yes you have to weld the block to the other blocks and it creates a chain…
That’s why you get the get the adjacent blocks using GetPartBoundsInBox and weld them…
AssemblyRootPart will become the baseplate once you weld. It is not relevant to welding.
Run code on the server of course.
Ngl I don’t really know what you’re talking about. He wants part to fall. The way you make parts fall in Roblox is by using the built in physics engine unless you want to spend years developing your own physics engine.
Dude youre not getting it. A physics-based system is terrible. Unity and Unreal engine suffer from this. It just isnt a roblox thing… its just bad practice.
Use physics on client. But validate on server in the method I provided above. Send the server simple data like position coordinates to check against to reduce network congestion. Further optimize by sending a 0.5 second interval in build mode when asking server to validate.
If its a single player game with no multiplayer like The Sims then what you describe is fine. Otherwise no. Just no.
Lmao this thread is hilarious. All the guy asked was how he could have his parts fall and you guys are telling him to make custom physics.
I don’t know if you realized we are in 2024 not 2004. The physics will work 100% perfectly. If you want the parts to fall in place than use Constraints.
Anyway, OP can decide how he wants to make the system, I am the only who provided actual code and not an abstract step by step list of ideas.
Thank you for all of this information, I will devote the next week of my life banging my head against a wall until something works and let you know if there’s anything else!
You don’t need too much information. I don’t know why the other people in this thread were giving you long complex solutions when you asked a simple question with a simple answer.