A Godot node that allows a 3D scene to use a standard 2D coordinate system.
About | Current Release |
---|---|
Version | 1.1 |
Date | July 7, 2023 |
Platform | Godot 4 |
License | MIT License |
Author | Brom Bresenham |
- Create a 3D scene.
- Add a Camera3D (default configuration is fine).
- Add Mode2DX.gd as a scene node.
- Drag the camera into the
camera
property of theMode2DX
node. - All children and subtrees of
Mode2DX
will use 2D coordinates. - (0,0) is top-left of the display.
$%Mode2DX.display_size
contains the current window size in pixels.Mode2DX
will automatically update its configuration if the screen size changes.- The scale * mesh size of each descendent node will be the pixel size it is drawn at.
- For example, a
MeshInstance3D
quad scaled to 100x50x1 will be 100x50 pixels onscreen (if positioned atz=0
as a child ofMode2DX
).
- For example, a
- Because
Mode2DX
inverts the Y axis relative to standard 3D scenes, caveats apply:- The
scale.y
property of each child node or subtree root must be negatated. For example, to have a quad be drawn at 100x50 pixels you would set itsscale
to(100,-50,1)
. - You should always take the
abs()
of aMode2DX
child node'sscale
before using it in computation. Because of the way that Godot stores 3D angles and scale in a combined "basis" form, you might setrotation=(0,0,0), scale=(1,-1,1)
in the editor but when the game runs the properties would berotation:(0,180,0), scale:(-1,-1,-1)
.
- The
- Mode2DX pairs well with the 3D Drawing Order Godot Engine modification.
This repo contains a sample project made in Godot 4.1-RC1. The only necessary file for your own projects is Mode2DX.gd, which you can copy out separately.