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

Why does raycasting detect random stuff?

I have a part that's in a moving model and a raycast that detects the bottom. Sometimes it just detects random stuff, like the parts ontop or the parts on the side even tho i set it to detect stuff from the bottom, and when the part is in another part it detects literally nothing. How do I go around fixing this?

local rayOrigin = model.Detector.Position
local rayDirection = Vector3.new(0,-1,0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {model.Detector}
    raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
    local raycastResult = game.Workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
    local hitPart = raycastResult.Instance
    print("something")
else if not raycastResult then
        print("nothing")
    end
end

1 comment

0

I don't 100% understand the question, but make sure you know the difference between blacklist and whitelist. With a blacklist (what you are using) anything in the FilterDescendantsInstances table will be ignored by the raycast. With a whitelist, ONLY what is in the FilterDescendantsInstances table will be detected by the raycast. In your case, model.Detector is being ignored, and everything else i

1 answer

You'd have to make rayDirection be based off the origin like so:

local rayOrigin = model.Detector.Position
local rayDirection = Vector3.new(1,-1,1)*mode.Detector.Position

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