Trouble with placement object collisions

Hello, I have recently started creating a furniture placement system and most of it has gone well except for the collisions. I have looked at a variety of different articles on the subject and have found that none have helped me. The Region3 is the only thing that got super close to working so far in my experimenting.

here is my current code…

function PlaceMod:CheckIntersections(Size, Position, Furniture)
	local Min = Position - (Size)
	local Max = Position + (Size)
	local Region = Region3.new(Min, Max)
	local Ignore = {Furniture, self.Plot}
	local Touching = game.Workspace:FindPartsInRegion3WithIgnoreList(Region, Ignore)
	if #Touching <= 0 then
		self.Colliding = false
	elseif #Touching >= 1 then
		self.Colliding = true
	end
end


function PlaceMod:Placing(Furniture, MouseMove)	
	local Snap = self:CalcPlot(Furniture, MouseMove)
	local RotateAngle = CFrame.Angles(0,self.Rotation,0)
	local CanvSize = (Vector3.new(math.abs(self.Plot.Size.X), math.abs(self.Plot.Size.Y), math.abs(self.Plot.Size.Z)))/2
	local ModelPos = Furniture.PrimaryPart.Position
	local PlotPos = self.Plot.Position
	local ModelSize = Furniture.PrimaryPart.Size/2
	local modelSize = CFrame.fromEulerAnglesYXZ(0, self.Rotation, 0) * Furniture.PrimaryPart.Size
	modelSize = Vector3.new(math.abs(modelSize.x), math.abs(modelSize.y), math.abs(modelSize.z))/2
	self:CheckIntersections(ModelSize, ModelPos, Furniture)
	self:CheckStatus(Furniture)
end

A friend has said to me that the issue may be happening because its a rectangle and when I rotate it it gets the opposite side but I tried turning it into a cube and the same issue still. I am no person for advanced math so if anyone knows some sort of fix that I can look into, that would be very much appreciated!

1 Like

Is there a hit box on each model? If so then that may be why!

2 Likes

Could you please link the game? @Taveple

1 Like

Try making the hitbox a tiny bit smaller, because it seems like Region3 counts juuuuust touching as being inside region, which messes things up for you.

You can do it procedurally by changing your code like this:

local SizeFuzz = Vector3.New(0.1, 0.1, 0.1)
Region = Region3.new(Min + SizeFuzz, Max - SizeFuzz)

Let us know if this works! :slight_smile:

1 Like

Why use Region3 when you can use “GetTouchingParts” for the hitbox and see if any of those touching parts are other placed objects. Even if the hotbox has can collide off, you can still do it with this code:

local function GetTouchingParts(part)
   local connection = part.Touched:Connect(function() end)
   local results = part:GetTouchingParts()
   connection:Disconnect()
   return results
end

local results = GetTouchingParts(workspace.PartA)
print(#results) --> 1

Holy, this was so close to working but it only worked in one area. I’ll try and mess around with it but its getting there! Screen capture - 473b892f97ec986c4202fe772c24e634 - Gyazo

1 Like

I’ve tried this already in multiple different forms but it did not work for me

1 Like

Here ya go, Factory tycoon - Roblox

1 Like