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

How to detect if there's anything between two points??

Asked by 2 years ago

I am making an npc which shoots even if there is a wall between the target and the npc.

How to make it so that it only shoots if its vacant between the npc's head and target?? Any help would be Highly Appreciated. Thanks in Advance.

1
raycasting Puppynniko 1059 — 2y

2 answers

Log in to vote
1
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
local function CheckBetween2Points(Point1:BasePart,Point2:BasePart)
    local vector = (Point2.CFrame.Position - Point1.CFrame.Position).Unit
    return workspace:Raycast(Point1.Position,vector*100)
end
Ad
Log in to vote
0
Answered by 2 years ago

Use raycasting (Docs) or more specifically, Raycast Filtering (Docs)

Answer this question