I am making a tower defence game, and I want to add a similar range effect to the one on Bloons TD 6. I want it so that if there is a collision in the way, it highlights in red (see attached image). I’m not really sure how to go about this. So far, to detect a collision, I have a raycast2D. If you knew how to go about this, that would be great!
Run a shader on everything that is an obstacle. Pass the circle center and the radius to those shaders via global uniforms and let them alter their color for pixels that are in range.
I have been running into a couple of issues when trying to implement this.
This is a 2D game, so I can not exactly project decals.
To my knowledge, shaders can only detect pixel colours (I’m not the best with shaders). If I wanted to add sprites to these obstacles, how could I detect the obstacles?
Shaders don’t need to “detect” anything. You decide which sprites represent obstacles and to such sprites you assign a shader that overlays the range circle over their normal appearance.
I just noticed a problem with this solution.
It does work as intended, but it does not colour the circle beyond the point of the collision object (see attached image). Is there another way I could achieve this effect?
I’m not sure I get what you mean. You can set the radius in the shader to be larger than collider’s radius. Those are not mutually dependent in any way.
Oh I think I get it. You want “shadows”. You’ll have to use LightOccluder2D nodes and a point light, render that into a separate viewport and composit it over the main viewport.