How would I go by making this ray spread out more

I’m trying to make a part (for testing) raycast and it works but I can’t seem to figure out how can I make the ray spread out more so it can be like a actual field of view for the AI

If it wasn’t clear, I need help making this spread out so it doesn’t see the player in a straight line

local originPosition = script.Parent.Position
local direction = (script.Parent.CFrame.LookVector * 300)
local result = workspace:Raycast(originPosition,direction,rayParams)

if result then
print(“I already made the check here”)
end

Most performant - Use a slightly offset magnitude detection. (Ex humanoidrootpart position + half the FOV)

Probably worse - do the same thing but using the position of where the ray hit.

Least performant but should work perfect - make extra rays with little offsets.

How often would you be using said raycast? If multiple npcs are using said raycast at a 300 stud distance it could get very laggy. I’d recommend looking into this article and using a similar solution How would I go about making an AOE Cone Spell like in All Star Tower Defense
Use a dot product calculation to determine if said item(s) is/are with-in the fov of the AI

1 Like