Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to detect if a Model is overlapped with another object?

I have some model, and they have random position, so I need to validate if the model is overlapped with another object (like player, car or also the same cloned model), but I can't figure out how to validate if the model is overlapped with another object, and validate is if that overlay is acceptable, because not all overlays are unacceptable.

You may be asking a very big question, but I'm a bit confused and I do not even know where to begin with this algorithm.

Any help would be appreciated.

1 comment

1 answer

✓ Accepted answer

Very accurately? You'll have to check every part in the model yourself. Generally? Use the functions Model:GetExtentsSize() and Model:GetModelCFrame() to create a relevant Region3 .

Like this:

wait(1)

local model = workspace:WaitForChild('Model') --path to any model

--model info
local size = model:GetExtentsSize()
local hsize = size/2
local pos = model:GetModelCFrame().p

--parameters for region
local lowp = pos - hsize
local highp = pos + hsize

local r3 = Region3.new(lowp,highp)

--optional warning box
local box = Instance.new('Part')
box.BrickColor = BrickColor.new('Really red')
box.Transparency=1
box.Anchored=true
box.CanCollide=false
box.CFrame = r3.CFrame
box.Size = r3.Size
box.Parent = workspace

--creating a manual ignore list is useful
local ignoreList = {}
--igore parts in the model
function fun(x) if x:IsA('BasePart') then table.insert(ignoreList,x) end end function scan(y) fun(y) for _,v in pairs(y:GetChildren()) do scan(v) end end scan(model)
--ignore parts such as baseplate
for _,v in pairs(workspace:GetChildren()) do if v:IsA('BasePart') then table.insert(ignoreList,v) end end

--in example:
while wait(1) do
	--most useful function!
	local parts = workspace:FindPartsInRegion3WithIgnoreList(r3,ignoreList,1000)
	if #parts>0 then
		box.Transparency=0.5
	else
		box.Transparency=0.9
	end
end

5 comments

0

I'ts is not exactly what I am loking for, because this code asume that the CFrame of the PrimaryPart is the center of the model, but also I see in code line 8 "model:GetModelCFrame().p", the function :GetModelCFrame() does not appears in the api, but I think I can modifie the code to get what I'm looking for

0

Thanks so mush

0

Hmm either briefly toggle the PrimaryPart or center it. I don't think there's a better way to get the center of a model.

0

I did not know that this method exists, in fact to invest days making a code to get the center of a model, this information does not appear in the API

0

btw I am not sure how you would collision detect another Region but OldPalHappy's comment might help.

This discussion is preserved as it was. New answers, comments, and votes are closed.