How do I set up a material that only shows up as a an intersection.

I try to figure out how to make a material that works like a decal but for cross sections of geometry?

I figured out a solution, but as you see, there are two issues with the material.
The first is that it renders on top of the character when the character stands in front of the mesh.
The second is that I get a weird edge.

I have no idea how this material works, I copied it of a forum post so if anyone have a suggestion of how I get rid of these issues, I’d be very grateful.



Also, my solution for the detection: