Raycasting Direction acting weird

My Raycasting system (whom I wish to use as a surveillance system for enemy robots) does not return any part even when I put the the robot in a closed room (as shown below) where it has to hit at some point. I tried with directions (0,-100,0) and those were the only instances where it hit.

RobloxScreenShot20210529_195151249
(indeed the ray detects no part here)

The script is as follows:

	local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {script.Parent.Parent.Head}
raycastParams.IgnoreWater = true

	local detection=workspace:Raycast(script.Parent.Parent.Head.Position, script.Parent.Parent.Head.CFrame.LookVector, raycastParams)
			if detection then
				print("successful!")
				part=Instance.new("Part",workspace)
			part.Anchored=true
			part.CanCollide=false
			part.Position=detection.Position
				game:GetService("Debris"):AddItem(part,5)
			else
				print("no ray :(")
			end
end

Any idea what might be the issue there?

Probably because if you just use LookVector, it’s going to act as a single single stud, you have ot multiply it by how far you want the guard to look. So basically, if you want it to look till 50 studs, multiply the lookvector by 50

Also, not sure if related, but it could be that it’s touching the guard itself, so also change

raycastParams.FilterDescendantsInstances = {script.Parent.Parent.Head}

To

raycastParams.FilterDescendantsInstances = {script.Parent.Parent}
1 Like

ooooooooooooh thank you i didn’t understand that

1 Like