Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

Camera3D

Inherits: Node3D < Node < Object

Inherited By: XRCamera3D

Camera node, displays from a point of view.

Description

Camera3D is a special node that displays what is visible from its current location. Cameras register themselves in the nearest Viewport node (when ascending the tree). Only one camera can be active per viewport. If no viewport is available ascending the tree, the camera will register in the global viewport. In other words, a camera just provides 3D display capabilities to a Viewport, and, without one, a scene registered in that Viewport (or higher viewports) can't be displayed.

Tutorials

Properties

CameraAttributes

attributes

int

cull_mask

1048575

bool

current

false

DopplerTracking

doppler_tracking

0

Environment

environment

float

far

4000.0

float

fov

75.0

Vector2

frustum_offset

Vector2(0, 0)

float

h_offset

0.0

KeepAspect

keep_aspect

1

float

near

0.05

ProjectionType

projection

0

float

size

1.0

float

v_offset

0.0

Methods

void

clear_current ( bool enable_next=true )

Projection

get_camera_projection ( ) const

RID

get_camera_rid ( ) const

Transform3D

get_camera_transform ( ) const

bool

get_cull_mask_value ( int layer_number ) const

Plane[]

get_frustum ( ) const

RID

get_pyramid_shape_rid ( )

bool

is_position_behind ( Vector3 world_point ) const

bool

is_position_in_frustum ( Vector3 world_point ) const

void

make_current ( )

Vector3

project_local_ray_normal ( Vector2 screen_point ) const

Vector3

project_position ( Vector2 screen_point, float z_depth ) const

Vector3

project_ray_normal ( Vector2 screen_point ) const

Vector3

project_ray_origin ( Vector2 screen_point ) const

void

set_cull_mask_value ( int layer_number, bool value )

void

set_frustum ( float size, Vector2 offset, float z_near, float z_far )

void

set_orthogonal ( float size, float z_near, float z_far )

void

set_perspective ( float fov, float z_near, float z_far )

Vector2

unproject_position ( Vector3 world_point ) const


Enumerations

enum ProjectionType:

ProjectionType PROJECTION_PERSPECTIVE = 0

Perspective projection. Objects on the screen becomes smaller when they are far away.

ProjectionType PROJECTION_ORTHOGONAL = 1

Orthogonal projection, also known as orthographic projection. Objects remain the same size on the screen no matter how far away they are.

ProjectionType PROJECTION_FRUSTUM = 2

Frustum projection. This mode allows adjusting frustum_offset to create "tilted frustum" effects.


enum KeepAspect:

KeepAspect KEEP_WIDTH = 0

Preserves the horizontal aspect ratio; also known as Vert- scaling. This is usually the best option for projects running in portrait mode, as taller aspect ratios will benefit from a wider vertical FOV.

KeepAspect KEEP_HEIGHT = 1

Preserves the vertical aspect ratio; also known as Hor+ scaling. This is usually the best option for projects running in landscape mode, as wider aspect ratios will automatically benefit from a wider horizontal FOV.


enum DopplerTracking:

DopplerTracking DOPPLER_TRACKING_DISABLED = 0

Disables Doppler effect simulation (default).

DopplerTracking DOPPLER_TRACKING_IDLE_STEP = 1

Simulate Doppler effect by tracking positions of objects that are changed in _process. Changes in the relative velocity of this camera compared to those objects affect how audio is perceived (changing the audio's AudioStreamPlayer3D.pitch_scale).

DopplerTracking DOPPLER_TRACKING_PHYSICS_STEP = 2

Simulate Doppler effect by tracking positions of objects that are changed in _physics_process. Changes in the relative velocity of this camera compared to those objects affect how audio is perceived (changing the audio's AudioStreamPlayer3D.pitch_scale).


Property Descriptions

CameraAttributes attributes

The CameraAttributes to use for this camera.


int cull_mask = 1048575

  • void set_cull_mask ( int value )

  • int get_cull_mask ( )

The culling mask that describes which VisualInstance3D.layers are rendered by this camera. By default, all 20 user-visible layers are rendered.

Note: Since the cull_mask allows for 32 layers to be stored in total, there are an additional 12 layers that are only used internally by the engine and aren't exposed in the editor. Setting cull_mask using a script allows you to toggle those reserved layers, which can be useful for editor plugins.

To adjust cull_mask more easily using a script, use get_cull_mask_value and set_cull_mask_value.

Note: VoxelGI, SDFGI and LightmapGI will always take all layers into account to determine what contributes to global illumination. If this is an issue, set GeometryInstance3D.gi_mode to GeometryInstance3D.GI_MODE_DISABLED for meshes and Light3D.light_bake_mode to Light3D.BAKE_DISABLED for lights to exclude them from global illumination.


bool current = false

  • void set_current ( bool value )

  • bool is_current ( )

If true, the ancestor Viewport is currently using this camera.

If multiple cameras are in the scene, one will always be made current. For example, if two Camera3D nodes are present in the scene and only one is current, setting one camera's current to false will cause the other camera to be made current.


DopplerTracking doppler_tracking = 0