Help! Need to add a 3D camera to 2D game

This is driving me a bit crazy, it feels like it should be very simple and straitforward, but it is not. I would like to have a perspective 3D camera pointing down out my 2D sprites at a slight angle. Thus far, my whole project is in 2D, and this is the only feature I need that is in 3D. Porting the entire project to 3D just to test out this one idea would be utter nonsense – hours and hours of tediously wasted time.

Surely there is a simple way to do this, no?

1 Like

Depending on what you mean by 3D you could use a skew shader to make the 2D get smaller as it’s further away.

1 Like

I thought about that, but is has a few problems:

  • assuming this is done via post processing (is it?), then there would have to be a lot of wasted rendering as many rendered pixels would get cut away from the skewed render

  • The math for doing the correct skew is actually extremely complex. It’s much harder than simply making closer objects appear larger

  • I’m worried about stretching and tearing problems

The best way, hands down, would be to use a 3D camera that was programmed specifically for a perspective view

You can do this using a SubViewport node and a Sprite3D with a viewport texture.

First, create an empty 3D scene. Add a SubViewport node and add your main 2D scene as a child of the SubViewport node.
Then, add a Sprite3D under the root node, and add a new ViewportTexture to it. When it asks you to select a Viewport, select the SubViewport node. Now your Sprite3D will display your 2D scene, and you can add a Camera3D under the root node to view it.

3 Likes

Very clever, thank you!

wait… there’s no material on Sprite3D, so that solution actually has a bit of a snag. How do I change the material of a Sprite3D?

You don’t need to change the material, only the texture. Select the Sprite3D and click the button next to the texture property at the top of the inspector. Then, select “New ViewportTexture” from the dropdown.

If you really do want to change the material, you could try changing the material of your main 2D scene instead.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.