• 2D
  • Mirrors - how do I make one?

So, I have a reflective surface in my 2D side-scrolling game. I want the player's reflection to show up in the surface. It will be on the wall, so I want it to be slightly in front of the player so that the player's sprite shouldn't cover its reflection. What is the best way to do this?

My idea is to create a duplicate sprite for the player character and set its animation to be the same as the player and its position to be slightly ahead of the player. I will somehow mask the sprite so that it only shows up in the mirror. But I'm sure there's a better way to do this.

Keep in mind that it's also a fairly expensive way to have reflections, but so long as you have only a few such mirrors it should be fine.

i didnt try this yet, but maybe can help u

Tried to follow along, got this bizarre error message:

Edit: Turns out I forgot a closing bracket. But I guess this could work for a reflection. Is this better than using a duplicate sprite?

Problem: the mirror only works when the sprite is BEHIND the mirror. I want the sprite to be on top of the mirror. What do?

So funny! I've been working on a mirror effect and visited the forums now only to ask about Camera2D culling to use for my mirror effect :D I've sortof got it to work with Viewports. It is a very naive implementation but I guess it can be built upon. I'll post more details here when I am done :)

Edit: The reason your mirror effect only works when the sprite is behind is that SCREEN_TEXTURE takes a screenshot of everything that has been rendered at that point. So if your sprite is above the mirror sprite it hasn't been rendered yet at the time your mirror shader is running.

I tried following your tutorial, but I get a "Node not found: Viewport" error even though I selected the viewport in the editor.

It seems the error was because of the order of the nodes, but once I fixed that, I still couldn't get the shader working. Anyway I ended up just using a duplicate sprite and a Light2D mask.