In a 2D Topdown project, i want to have a view circle around the player to show areas hidden by walls.
It works like this:
the lower tile of the walls have a box collider
raycasts from the player position collide with those colliders
the hit point positions are used to generate a mesh used as a mask
this mask hides upper wall and ceiling tiles within it
The problem is, that ceiling tiles can be on the same tile as lower wall tiles. Then the raycasts can never reach this area, and so these tiles are never within the mesh mask.
Can be seen in the second half this video:
lmylbs
Eventually it could work if the raycasts would be allowed to go “into” the box colliders, but not get out again if that makes any sense.
Different idea: get cells underneath player. Alpha the tiles with tilemap.SetColor(cell, alphadColor). This would let you do a 50% alpha which might look pretty good. You can see a similar effect in for example Hades, see here at 20 second mark. When you’re behind a pillar, it alphas. This would also be slightly cheaper too.
You could even collect cells more widely below the player and feather in/out the alphaing with more transparency toward the center. In all cases, you’d need to keep track of the alpha’d cells to ensure you restore them to opaque.
You don’t necessarily need to use the physics system to find these tiles. You could collect from a tilemap dedicated to tall objects.
I see your problem there,
Are your ceiling tiles & floor tiles actually the same tile or two separate tiles on top of each other? I’m wondering if you couldn’t make them part of two different layers and then cast & mask only the layer that you want.
Otherwise Lo-renzo’s idea sounds like a nice and potentially cheaper alternative
If i do it per pixel or per tile does not matter (which is the cheaper alternative if you got you right?).
Those tiles are already on different tilemaps within the same grid, and the mask already only affects the upper wall and ceiling tiles.
I want only areas to be affected which are visible to the player, which means areas that can be hit by a raycast from the player. But those raycasts can never hit those ceiling tiles when a ground wall tile (which of course block visibility) is behind it
I extruded the generated mesh by the height of one tile upwards. It is now a view-egg instead of a view circle, but it does exactly what i wanted it to do