Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does raycasting detect random stuff?

Asked by 3 years ago
Edited 3 years ago

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
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 ThatPreston 354 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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
Ad

Answer this question