ID:166232
 
How would I go about making it so that mobs could only see a certain distance/area in front of them? Like those nifty vision-cones you see all too often in commercial games.
i'm not sure how to do it, but i think it has to do with either eye_perspective or range()
Seraphrevan wrote:
How would I go about making it so that mobs could only see a certain distance/area in front of them? Like those nifty vision-cones you see all too often in commercial games.

See luminosity, and/or client.view.
In response to DivineO'peanut
I think you're misunderstanding me. I know how to make it so that you can only see things within a certain radius around yourself, but I want it so that I can make NPCs only detect things directly in front of them (which I think I have an idea of how to do), and off to the sides a little bit. You know, like those vision cones in games. They can't see behind or too far to the sides, and they also can only see so far.
You can do it by looking at all the tiles in the player's screen, and checking if the player is facing the general direction. Here is an example on how one would work.

proc/cone_turfs(atom/A)
var/list/objects = list()
for(var/turf/T in view(A))
if((get_dir(A, T) & A.dir) || (A.loc == T))
// if the direction from the center to the target is in the general direction, add it
objects += T
return objects


In order to make it so the player can only see the turfs, you would have to use screen objects, and block off the view dynamically.

~~> Unknown Person
In response to Unknown Person
Where exactly does B come in? Or was that supposed to be T?
In response to Seraphrevan
Whoops. I was modifying part of it, and I forgot to change it. I edited my post.
I asked a very similar question a few months back when working on a camera object. I was given this, which returns a list of locations/turfs in a cone. With a little work you could adapt it into your code like I did mine.
proc/cone(atom/target, dist = 2, dir)
var/list/L[0]
var/turf
T = target; T2
for(var/index = 1 to dist)
T = get_step(T, dir)
L += T
for(var/D in list(turn(dir, 90), turn(dir, -90)))
T2 = T
for(var/index2 = 1 to index - 1)
T2 = get_step(T2, D)
L += T2
return L

Should be self-explanatory.