Hi ya’ll, how to create player vision cone in 2d like in the game Darkwood. The enemies are only visible when inside the player’s vision cone. And things can occlude other things from being visible.
I have looked at sample-lights-and-shadows repo (the sample in the repo works fine, but when I try to recreate it in my projects i don’t work) and I’m not sure how to tweak it so the the occluded objects don’t render.
This may not be the solution you are looking for but I used this approach on a game to use the flashlight for monster detection:
You can create a file with .convexshape extension and paste this
shape_type: TYPE_HULL
data: 160.0
data: -50.0
data: 0.0
data: 160.0
data: 160.0
data: 0.0
data: -80.0
data: 50.0
data: 0.0
--Change the values as you like
After that, on your player, add a collision component. For the shape, select the convexshape. Set the type to trigger.
Start all enemies (and any object that should be invisible when not looked at) as invisible. On the player script, check for trigger area enter and exit. If enter is true, set the visibility to true. If false, set it to false.
For the light, using a yellow triangle (or 60 degree circle) image with transparency set to 0.6 that matches the collision shape.