so i am working on a placement system, but the collision script is not working as intended.
here is the script, also i am using the rotated region 3 module, but i have tried the normal one and it still didnt work
local region2 = RR3.new(hitbox.CFrame,hitbox.Size-Vector3.new(0.1,0.1,0.1))
local ignorelist = {}
for i,v in pairs(game.Players:GetChildren()) do
table.insert(ignorelist,v.Character)
end
local parts2 = region2:FindPartsInRegion3WithIgnoreList(ignorelist)
for i,v in pairs(parts2) do
if v.Name == "Hitbox" and v ~= hitbox then
canPlace = false
end
end
You could make the dropper Collidable with other objects already placed. I’m not sure if this would work with your system but it would be a simple solution.
Not a solution but more a suggestion. I’d rework your logic and map the entire base into a matrix instead. This would make it very easy to keep track of where your objects are located at and where you can’t / can place them.
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
local function CheckCollision(instance)
local IsColliding = false
if instance:IsA("Model") then
for _,z in pairs(instance:GetChildren()) do
local result = GetTouchingParts(z)
for i,v in pairs(result) do if v:IsDescendantOf(instance) then table.remove(result,i) end end
if #result ~= 0 then
IsColliding = true
break
end
end
end
if instance:IsA("BasePart") then
local result = GetTouchingParts(instance)
if #result ~= 0 then IsColliding = true end
end
return IsColliding
end
Personally i solve this by using :GetTouchingParts() and checking with it every frame while placing an object.I solve the CanCollide problem by turning on collisions right before running the check and then turning it off immediately after.
Here is an example that i use and it works perfectly:
CanPlace = true
GhostObj.Base.CanCollide = true --GhostObj is the clientside object that i move, Base is the "hitbox".
for i,v in pairs(GhostObj.Base:GetTouchingParts()) do
if not v:IsDescendantOf(GhostObj) and v ~= workspace.Baseplate then
CanPlace = false
end
end
GhostObj.Base.CanCollide = false
if CanPlace then
print("object is not colliding with anything")
end
I obviously recommend doing this same check on the server, once the player places the object. Can’t trust the client.
thanks for the reply, i do appreciate any help at all, but i have already tried and got the same result
but ill still try again just to make sure it doesnt work
You’re shrinking the size of the region to check in by v3(.1, .1, .1). I’m not sure how your Rotated Region3 module works, but it might be failing to detect the collision when both props are in the identical spot because the hitbox faces are outside of the region. (Which would be expected if the module uses raycasting for collision detection)
I use AxisAngle’s Rotated Reg3 module for placement detection. It has similar functionality to the rotated region3 module you used, but correctly detects a collision even if the part’s faces exceed the region bounds.
The syntax translates as
local region = RotatedRegion3.new(hitbox.CFrame, hitbox.Size)
local collisionParts = region:Cast(ignorelist)
for _, part in ipairs(collisionParts) do
if v.Name == "Hitbox" and v ~= hitbox then
canPlace = false
end
end
As an optimization for my placement system, I use region:CastParts(parts) to do a whitelisted collision check, instead of the blacklisted ignore approach. parts would be an array of all the already placed hitboxes.