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

Detecting if a Monster has "Vision" of a player?

Asked by
bobder2 135
10 years ago

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.

0
This is not a request site! xImmortalChaos 565 — 10y
0
No idea, good luck though. I would probably go forward with raycasting if I were you, since you wouldn't have to cover every area with rays since characters are kind of fat, they wouldn't be able to hide in small gaps. between rays. Perci1 4988 — 10y
0
@xImmortalChaos I'm not asking for someone to do the scripting, I'm asking if there's any other ways to do it. Fortunately @damagex443 was nice enough to give me an example script to use. bobder2 135 — 10y
0
@Perci1 Thanks for the feedback. I've got a functioning FOV system with help from @damagex443 that's using raycasting bobder2 135 — 10y

1 answer

Log in to vote
2
Answered by 10 years ago

I've actually made a script that does this, you can use it if you want.

01local fov = 90 -- This is the monsters field of view
02local dist = 50 -- This is the monsters view distance
03local monster = script.Parent.Parent.Character.Head -- Change this to the monsters position
04 
05function 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
View all 40 lines...
0
Thank you, this helps a lot! bobder2 135 — 10y
Ad

Answer this question