Block Placement System

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!

Edit: It is a grid system!

1 Like

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)

Demo:

4 Likes

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)

Hope this helps! Good luck!

3 Likes

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.

2 Likes

U can use welds like @batteryday suggested but instead using GetPartBoundsInBox,
use AssemblyRootPart

@Harisaiyo’s apporach is good tho, u can just unanchor them if they aren’t connected to a part.

1 Like

What does this mean?

The point of GetPartBoundsInBox is so that you can weld the part to adjacent parts.

Before you weld the block, the AssemblyRootPart will just be the block itself.

Here you can learn how assemblies work.

2 Likes

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.

2 Likes

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

3 Likes

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.

2 Likes

Don’t do this, awful system. Don’t rely on physics, you can easily do this with math and programming.

3 Likes

Yeah Roblox physics in really terrible and awful. That’s why 99.99% of games including every top game use it. :joy:

2 Likes

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.

3 Likes

I was gonna say something about validation but your perspective on it, blow my mind, thats awesome apporach.

4 Likes

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.

3 Likes

Here is a demo video of what happens when you break all welds when a part isn’t grounded.

If you don’t want the parts to fall individually you can just remove the code that breaks welds

2 Likes

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!

1 Like

:joy: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.

1 Like

Its helpful, I’m just going to try them all and see what works best.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.