Open Mooses2k opened 3 years ago
Stewie may just use expanding Area spheres to start with, but there's an option to use bouncing across the navmesh as well, which, since it's in 2D, should be performant.
As discussed on Discord, this is for the player's created light area from held light sources, so your idea then was:
"Two areas intersect, in that interested area, choose a point snapped to a grid inside it. Then light source raycasts to that point and if a shadow isn't cast, enemy raycasts to that same point"
Alek has a version working and will integrate it soon.
After AI fixes, it seems it's clear this feature isn't working yet.
Player moving light-source detection:
idea is even if they enemy can't see the player, they can see light from player's lightsources
Not quite as easy as it seems.
A FEW WAYS IT COULD BE DONE
RANDOM RAYCASTS TO PLAYER'S LIGHT AREA IF IN VISION CONE
Reverse could be light could use raycasts from the vision field of the enemy to detect the player's light radius (random point in an Area or the light's AABB?) This is pretty wasteful. Will miss a lot, but pretty simple.
SPHERECAST FROM PLAYER'S LIGHT THEN FROM IMPACT TO ANY VISION CONE OWNER IT'S INSIDE OF
Can be random point in the cone or area or perhaps one or maybe four compass point raycasts from edges of cone lights or 12 evenly in a circle (since no z-levels at the moment) for omnilights. Expensive but accurate.
MODULAR PIECES & OBJECTS HAVE LIT_BY_PLAYER, RAYCASTS CYCLING BETWEEN LIT_BY_PLAYER OBJECTS IN VISION CONE
Maybe for this, have a meta of each wall, ceiling, floor be is_lit_by_player...using, well, using existing lighting code would be best maybe... check if ray from player's light hits the wall anywhere, call it lit_by_player; AI raycasts one a frame cycling through any player lit walls in its vision_cone to see if not obstructed, in which case, partial player detection. Pillars and far sides of large objects are edge cases that might not work well.
ROOM-BASED
Maybe just room based...if a room (or nearest corridor) with a player with a light is within their vision cone, raycast to random points in it, 1-4 a second...maybe raycast check random walls (rarely floors or ceilings) within vision cone and player light Area
NOTE
Last step should typically be a raycast back to the player's light to confirm.
Maybe there's no way to avoid just random raycasting a few times a second from each enemy vision cone and doing all sorts of my detection stuff there, such as silhouette checking, changed position of items/doors,
One raycast per frame, changing target each frame, is probably not too expensive. Keep more exact/more likely to succeed checks more rarely (every 5-15 frames or so) as they're not needed as often
ALSO: lights are detectable at something like 100x the range of their lit radius. You can see a pinpoint of light from a long ways away. Pretty much any moving light in LOS of AI should be almost immediately detected at basically any range. They should not immediately know it's the player, though. Maybe simulate this by basically 10xing the light_level of a player with a lit light equipped.