Im trying to create a grid based placement system but I tried a lot of stuff but it doesn’t work. This is the code I have now for the collision detection:
local RotatedRegion3 = require(game.ReplicatedStorage.RegionModule)
local IsSpawning = false
local CurrentDecoy = nil
local GridSize = 3
local placetower = game.ReplicatedStorage.remotes.placetower
local canPlace = true
mouse.Button1Down:Connect(function()
if (IsSpawning == false) or (CurrentDecoy == nil) then return end
local part = mouse.Target
local indicator = CurrentDecoy.Indicator
if part ~= nil and part.Name == "Placeable" then
local region = RotatedRegion3.new(indicator.CFrame, indicator.Size)
local ignorelist = {}
for i,v in pairs(game.Players:GetChildren()) do
table.insert(ignorelist,v.Character)
end
local collisionParts = region:Cast(ignorelist)
for _, part in ipairs(collisionParts) do
print(part.Name)
if part.Name == "HumanoidRootPart" then
canPlace = false
else
canPlace = true
end
end
if canPlace == true then
placetower:FireServer(CurrentDecoy.Name, CurrentDecoy.CFrame)
indicator:Destroy()
CurrentDecoy:Destroy()
CurrentDecoy = nil
IsSpawning = false
end
end
end)
It’s probably that you’re not using the rounded position for the Region check. Alternatively, you could also probably just use GetTouchingParts as an easier but possibly less accurate method. Additionally, there is a somewhat new instance called OverlapParams that seems to be better than either Touch or Region3, though I have not tested it myself yet.
Basically just pick a part (preferably a hitbox that covers the entire model) and do Part:GetTouchingParts() to retrieve a table of touching parts. This will include every touching part that it detects, so you will have to take into account parts that would always be colliding (such as the rest of the model). So in short, get an array of touching parts from one part, then sort of filter out the ones you don’t want to detect.