Creating dynamic field of vision

First of all, I’m new to defold and I want to try it out with my idea.

I want to create something like top-down fast paced shooter. I want to have a good dynamic vision system on my tilemap (map created by external editor Tiled). See gif (https://i.imgur.com/POVXxgE.gifv) - this is what I want to achieve. This gif is from my Unity implementation. I have translated this algorithm (https://github.com/legends2k/2d-fov) from javascript to C#.

For this algorithm to work I need to get all world geometry. The more polygons it has the slower everything becomes, that means world geometry must also be optimized (tile colliders merged wherever possible). My collisions are in tilesource.

To create the vision effect I have dynamically created a vision mesh based on algorithm’s output and applied custom shaders to the map and this mesh. Actual map is visible only through the vision mesh. Everything around it is a separate gray scale version of the map (dynamically created during map load).

My questions are:

  1. How to get the world geometry and optimize it for passing to the vision algorithm? I don’t need optimization algorithms (I have them in C#), I need to know how to handle that in Defold.
  2. How to organize the project? How exactly should I put these algorithms into defold? Best practices?
  3. How to build dynamic vision polygon at runtime?
  4. Is there an easier way to achieve the visual effect I desire?
2 Likes

You can’t build polygon in runtime. One of workarounds is use collada model and shader. 2d light implemetations
Second way to use shader for casting rays. Problem with shader

1 Like

Thanks, now I have the rough idea how to approach this.

However, I’m still at a loss on how to get map colliders. I can’t find where they are stored.

You can’t access the physics data so you will have to build some representation of it yourself: export from tiled or similar.

1 Like

Thanks, I’ll dig deeper into this approach… if I return to Defold after I check out other 2d game engines.