How to detect if there is a part between 2 models

image

I want to detect if there is a part between dummy and dummy 2. I used a raycast but it keeps returning nil

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {workspace.Dummy}


local PartOnRay = workspace:Raycast(workspace.Dummy["HumanoidRootPart"].CFrame.p,workspace.Dummy2["HumanoidRootPart"].CFrame.p,raycastParams)


print(PartOnRay)
1 Like

Because the second value is a direction vector, not a position one. Try setting the second one as dir with the following code before it:

local vec = workspace.Dummy2.HumanoidRootPart.CFrame.p - workspace.Dummy.HumanoidRootPart.CFrame.p
local dir = vec.Unit * vec.Magnitude --this is the value you want