Introduction to 3D¶

Creating a 3D game can exist challenging. That actress Z coordinate makes many of the common techniques that helped to make 2D games simple no longer work. To aid in this transition, it is worth mentioning that Godot uses similar APIs for 2D and 3D. Most nodes are the aforementioned and are present in both 2D and 3D versions. In fact, it is worth checking the 3D platformer tutorial, or the 3D kinematic character tutorials, which are almost identical to their 2D counterparts.

In 3D, math is a little more circuitous than in second, and then also checking the Vector math entry in the wiki (which was especially created for game developers, not mathematicians or engineers) volition aid pave the fashion for y'all to develop 3D games efficiently.

Spatial node¶

Node2D is the base node for 2nd. Command is the base of operations node for everything GUI. Following this reasoning, the 3D engine uses the Spatial node for everything 3D.

../../_images/tuto_3d1.png

Spatial nodes have a local transform, which is relative to the parent node (every bit long as the parent node is too of or inherits from the blazon Spatial). This transform tin be accessed equally a 4×3 Transform, or equally 3 Vector3 members representing location, Euler rotation (Ten, Y and Z angles) and scale.

../../_images/tuto_3d2.png

3D content¶

Unlike 2D, where loading prototype content and drawing is straightforward, 3D is a piddling more difficult. The content needs to be created with special 3D tools (usually referred to as DCCs) and exported to an exchange file format in order to be imported in Godot (3D formats are not as standardized equally images).

DCC-created models¶

At that place are ii pipelines to import 3D models in Godot. The first and nearly common one is by Importing 3D scenes, which allows you to import unabridged scenes (simply every bit they look in the DCC), including blitheness, skeletal rigs, blend shapes, etc.

The second pipeline is by importing simple .OBJ files equally mesh resources, which tin be so put inside a MeshInstance node for brandish.

Generated geometry¶

Information technology is possible to create custom geometry by using the ArrayMesh resource directly. Simply create your arrays and use the ArrayMesh.add_surface_from_arrays() function. A helper course is besides available, SurfaceTool, which provides a more straightforward API and helpers for indexing, generating normals, tangents, etc.

In any example, this method is meant for generating static geometry (models that volition not exist updated oftentimes), every bit creating vertex arrays and submitting them to the 3D API has a meaning functioning cost.

2nd in 3D¶

While Godot packs a powerful 2nd engine, many types of games utilize 2D in a 3D surroundings. By using a stock-still camera (either orthogonal or perspective) that does not rotate, nodes such equally Sprite3D and AnimatedSprite3D can exist used to create second games that take advantage of mixing with 3D backgrounds, more than realistic parallax, lighting/shadow furnishings, etc.

The disadvantage is, of grade, that added complication and reduced operation in comparison to patently 2D, as well every bit the lack of reference of working in pixels.

Environment¶

Also editing a scene, it is oft common to edit the environment. Godot provides a WorldEnvironment node that allows changing the groundwork color, style (as in, put a skybox), and applying several types of born post-processing effects. Environments tin can also exist overridden in the Photographic camera.

3D viewport¶

Editing 3D scenes is done in the 3D tab. This tab tin be selected manually, but information technology will be automatically enabled when a Spatial node is selected.

../../_images/tuto_3d3.png

Default 3D scene navigation controls are similar to Blender (aiming to accept some sort of consistency in the free software pipeline..), but options are included to customize mouse buttons and behavior to be similar to other tools in the Editor Settings:

../../_images/tuto_3d4.png

Coordinate arrangement¶

Godot uses the metric system for everything in 3D, with 1 unit existence equal to i meter. Physics and other areas are tuned for this scale. Therefore, attempting to utilise a different scale is usually a bad thought (unless yous know what you are doing).

When working with 3D avails, it'southward ever all-time to work in the correct scale (set your DCC to metric). Godot allows scaling post-import and, while this works in most cases, in rare situations it may introduce floating-point precision issues (and thus, glitches or artifacts) in fragile areas such equally rendering or physics. Make sure your artists always piece of work in the right scale!

The Y coordinate is used for "up", though for most objects that demand alignment (similar lights, cameras, capsule collider, vehicle, etc.), the Z axis is used as a "pointing towards" direction. This convention roughly means that:

  • X is sides

  • Y is up/downwardly

  • Z is front/back

Space and manipulation gizmos¶

Moving objects in the 3D view is washed through the manipulator gizmos. Each axis is represented by a color: Ruby, Greenish, Blue represent X, Y, Z respectively. This convention applies to the grid and other gizmos too (and also to the shader language, ordering of components for Vector3, Color, etc.).

../../_images/tuto_3d5.png

Some useful keybindings:

  • To snap placement or rotation, press Ctrl while moving, scaling or rotating.

  • To center the view on the selected object, press F.

Default environment¶

When created from the Project Managing director, the 3D environment has a default sky.

../../_images/tuto_3d8.png

Given how physically based rendering works, it is brash to ever endeavour to work with a default environment in social club to provide indirect and reflected low-cal to your objects.

Cameras¶

No matter how many objects are placed in the 3D space, cipher will be displayed unless a Camera is besides added to the scene. Cameras can work in either orthogonal or perspective projections:

../../_images/tuto_3d10.png

Cameras are associated with (and only display to) a parent or grandparent viewport. Since the root of the scene tree is a viewport, cameras will display on it by default, but if sub-viewports (either as render target or picture-in-picture) are desired, they need their ain children cameras to display.

../../_images/tuto_3d11.png

When dealing with multiple cameras, the following rules are enforced for each viewport:

  • If no cameras are present in the scene tree, the first i that enters it will become the agile camera. Further cameras entering the scene will be ignored (unless they are set as current).

  • If a camera has the "current" property set, information technology will exist used regardless of any other photographic camera in the scene. If the property is prepare, it volition get active, replacing the previous camera.

  • If an active camera leaves the scene tree, the first camera in tree-lodge will take its place.

Lights¶

Godot has a limit of up to viii lights per mesh. Aside from that, there is no limitation on the number of lights, nor of types of lights, in Godot. As many as desired can be added, equally long equally performance allows, and no more than than viii lights shine on a single mesh.