How to use mesh as a mask?
With a boolean modifier
You had it right with either of these solutions. I would use the first one. But as you noticed, the cube mask hides the part you want to show. Select the cube and go into object properties and set the viewport display to &quot;Wire&quot;. also don't forget to uncheck &quot;Render&quot; in the visibility so it doesn't appear in your animation.

Then Select the road object, add a boolean modifier set to &quot;intersect&quot; and pick the cube mask.
Now you can either move the mask or the road to get the desired effect.

With a custom shader
You can limit the visibility of the road with a custom shader. You then don't have to use a mask object, and you won't have boolean artifacts, but the drawback is the mesh doesn't get &quot;cut&quot; on the edges of where it needs to stop displaying.
Select the road, go into the shading editor and add a new shader. Let's say you want the
road to display between y = - 1 and y = 1.
Add this setup to visualize the alpha of the material (1 is white, meaning the material is opaque. 0 is black, meaning the material is transparent):

Plug it into the alpha input of a principled bsdf shader and connect the bsdf to the material output. In the right hand side panel, go to options and set the blend mode to &quot;Alpha Clip&quot;.

Result :