im working on the melee part of my npc ai script and in order to attack i fire a raycast from the npc’s head towards the players head, but for some reason it returns nil, even though the raycast is fired towards the head and the head is the only whitelisted part?
edit: it does actually work, but rarely. only like 3% of the time, so very inconsistent
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Include
Params.FilterDescendantsInstances = {currentPlr.Character.Head}
local results = workspace:Raycast(npc.Head.Position,CFrame.new(npc.Head.Position,currentPlr.Character.Head.Position).LookVector,Params)
print(results)
the LookVector that you’re passing into :Raycast() has a length of 1, which I don’t think you are intending to do…
local RayDistance = 15
local P0 = npc.Head.Position
local P1 = currentPlr.Character.Head.Position
local C0 = CFrame.lookAt(P0, P1)
local results = workspace:Raycast(P0, C0.LookVector * RayDistance, Params)