I'm looking to make a stealth-based AI for a game that some friends and I are working on, although I don't know what to do for the monster's vision. My ideas so far have been:
Raycasting, I came up with this idea before I really knew what it was and realized I would have to do hundreds and hundreds of raycastings per second to cover the entire "FOV" of the monsters.
Welding cones made of corner bricks to the monster's face, problem with this is that the cone would make the monster turn slow.
Using a script to position cones from the above idea in-front of the monster's head, simulating a line of sight, while allowing the monster faster turning.
I've actually made a script that does this, you can use it if you want.
01 | local fov = 90 -- This is the monsters field of view |
02 | local dist = 50 -- This is the monsters view distance |
03 | local monster = script.Parent.Parent.Character.Head -- Change this to the monsters position |
04 |
05 | function MakeRay(startPos, endPos, show) -- Creates a new ray |
06 | local ray = Ray.new(startPos, endPos) |
07 | local obj, endPoint = Workspace:FindPartOnRay(ray) |
08 | if show then -- This is for debugging. It will make the rays visible |
09 | local rayPart = Instance.new( "Part" , Workspace) |
10 | rayPart.Name = "RayPart" |
11 | rayPart.BrickColor = BrickColor.new( "Bright red" ) |
12 | rayPart.Transparency = 0.5 |
13 | rayPart.Anchored = true |
14 | rayPart.CanCollide = false |
15 | rayPart.TopSurface = Enum.SurfaceType.Smooth |