So basically I have a placement system and I want to have it so that a block doesn’t go inside another block.
I have seen people do it so that the block turns red but I don’t really want that.
So basically I have a placement system and I want to have it so that a block doesn’t go inside another block.
You could add some code where the previous block that was placed would have some instance in it and the placement code if it detects a instance that filters parts from being created in one place, it wouldn’t be able to be placed on, don’t know much about placement systems and stuff but if this doesn’t solve your issue, good luck.
Well, I not sure about that but right now I’m working on a solution which includes raycasting and checking if there is a part and then offsetting it to the side of the block.
You could use that, if it is still broken and there’s no one to help you could watch a placement tutorial on YT and learn some stuff to add some filter to prevent double placing.
Well, the issue is storing the placement data. You could have stored the data on if a part has a block placed or not. However, it might be too much data to use a table or values for.
That’s not my problem, I have a folder called “PlacedBlocks” and whenever a block is placed it gets stored there. I am trying to detect if a block is inside another block.
If two blocks have an equivalent Vector3 position then you know if it’s inside or not.
Yep, that’s what I did but I don’t know what to do next. I have to move the block out of the way but the direction is important.
Alternatively you can just cancel the placement.
That would be too easy, however, so just check where the player / camera is located and place the block to the direction of the player / camera.
How would I do that? Would I check to see which face of the block is closest to the camera?
Well, I’d say you can do so, and I don’t really have anything else to think of in this situation.
You can use a .Touched
event or part:GetTouchingParts()
to check if something is colliding with another object.
Yes but how would that help with my solution?
I tried the method but it kept on moving like this. Can someone help me fix this?
Here’s some code:
local ClosestDistance = 10
local Closest
ocal targ = mouse.Target.Parent.PrimaryPart
local PosTable = {targ.Position + Vector3.new(targ.Size.X, 0, 0), targ.Position - Vector3.new(targ.Size.X, 0, 0), targ.Position + Vector3.new(0, 0, targ.Size.Y), targ.Position - Vector3.new(0, 0, targ.Size.Y)}
for i, v in pairs(PosTable) do
local mousePos = mouse.Hit.p
local distance = (mousePos - v).Magnitude
if distance < ClosestDistance then
ClosestDistance = distance
Closest = v
end
end
block.PrimaryPart.Position = Closest
return
Here’s a video:
I’m not adding onto any position or cframe so I don’t know what the problem is.
Have you tried using IsRegion3Empty
to detect if the part intersected with another?
EDIT
I would recommend when the mouse moves with the block (assuming you’re using Mouse.Move).
Ok I’ll look into that. Where would I put a region3 though?
I have a script that checks if any other block has the same position and then alerts to move the block somewhere else.
Now that I think of it, I am using RunService.RenderStepped. I’ll change it to mouse.Move.