Class Node3D
- Namespace
- Godot
- Assembly
- GodotSharp.dll
Most basic 3D game object, with a Transform3D and visibility settings. All other 3D game objects inherit from Node3D. Use Node3D as a parent node to move, scale, rotate and show/hide children in a 3D project.
Affine operations (rotate, scale, translate) happen in parent's local coordinate system, unless the Node3D object is set as top-level. Affine operations in this coordinate system correspond to direct affine operations on the Node3D's transform. The word local below refers to this coordinate system. The coordinate system that is attached to the Node3D object itself is referred to as object-local coordinate system.
Note: Unless otherwise specified, all methods that have angle parameters must have angles specified as radians. To convert degrees to radians, use @GlobalScope.deg_to_rad
.
Note: Be aware that "Spatial" nodes are now called "Node3D" starting with Godot 4. Any Godot 3.x references to "Spatial" nodes refer to "Node3D" in Godot 4.
public class Node3D : Node, IDisposable
- Inheritance
-
Node3D
- Implements
- Derived
- Inherited Members
Constructors
Node3D()
public Node3D()
Fields
NotificationEnterWorld
public const long NotificationEnterWorld = 41
Field Value
NotificationExitWorld
public const long NotificationExitWorld = 42
Field Value
NotificationLocalTransformChanged
Node3D nodes receive this notification when their local transform changes. This is not received when the transform of a parent node is changed.
In order for NotificationLocalTransformChanged to work, users first need to ask for it, with SetNotifyLocalTransform(bool).
public const long NotificationLocalTransformChanged = 44
Field Value
NotificationTransformChanged
Node3D nodes receive this notification when their global transform changes. This means that either the current or a parent node changed its transform.
In order for NotificationTransformChanged to work, users first need to ask for it, with SetNotifyTransform(bool). The notification is also sent if the node is in the editor context and it has at least one valid gizmo.
public const long NotificationTransformChanged = 2000
Field Value
NotificationVisibilityChanged
Node3D nodes receive this notification when their visibility changes.
public const long NotificationVisibilityChanged = 43
Field Value
Properties
Basis
Direct access to the 3x3 basis of the Transform property.
public Basis Basis { get; set; }
Property Value
GlobalBasis
Global basis of this node. This is equivalent to global_transform.basis
.
public Basis GlobalBasis { get; set; }
Property Value
GlobalPosition
Global position of this node. This is equivalent to global_transform.origin
.
public Vector3 GlobalPosition { get; set; }
Property Value
GlobalRotation
Rotation part of the global transformation in radians, specified in terms of YXZ-Euler angles in the format (X angle, Y angle, Z angle).
Note: In the mathematical sense, rotation is a matrix and not a vector. The three Euler angles, which are the three independent parameters of the Euler-angle parametrization of the rotation matrix, are stored in a Vector3 data structure not because the rotation is a vector, but only because Vector3 exists as a convenient data-structure to store 3 floating-point numbers. Therefore, applying affine operations on the rotation "vector" is not meaningful.
public Vector3 GlobalRotation { get; set; }
Property Value
GlobalRotationDegrees
Helper property to access GlobalRotation in degrees instead of radians.
public Vector3 GlobalRotationDegrees { get; set; }
Property Value
GlobalTransform
World3D space (global) Transform3D of this node.
public Transform3D GlobalTransform { get; set; }
Property Value
Position
Local position or translation of this node relative to the parent. This is equivalent to transform.origin
.
public Vector3 Position { get; set; }
Property Value
Quaternion
Access to the node rotation as a Quaternion. This property is ideal for tweening complex rotations.
public Quaternion Quaternion { get; set; }
Property Value
Rotation
Rotation part of the local transformation in radians, specified in terms of Euler angles. The angles construct a rotation in the order specified by the RotationOrder property.
Note: In the mathematical sense, rotation is a matrix and not a vector. The three Euler angles, which are the three independent parameters of the Euler-angle parametrization of the rotation matrix, are stored in a Vector3 data structure not because the rotation is a vector, but only because Vector3 exists as a convenient data-structure to store 3 floating-point numbers. Therefore, applying affine operations on the rotation "vector" is not meaningful.
Note: This property is edited in the inspector in degrees. If you want to use degrees in a script, use RotationDegrees.
public Vector3 Rotation { get; set; }
Property Value
RotationDegrees
Helper property to access Rotation in degrees instead of radians.
public Vector3 RotationDegrees { get; set; }
Property Value
RotationEditMode
Specify how rotation (and scale) will be presented in the editor.
public Node3D.RotationEditModeEnum RotationEditMode { get; set; }
Property Value
RotationOrder
Specify the axis rotation order of the Rotation property. The final orientation is constructed by rotating the Euler angles in the order specified by this property.
public EulerOrder RotationOrder { get; set; }
Property Value
Scale
Scale part of the local transformation.
Note: Mixed negative scales in 3D are not decomposable from the transformation matrix. Due to the way scale is represented with transformation matrices in Godot, the scale values will either be all positive or all negative.
Note: Not all nodes are visually scaled by the Scale property. For example, Light3Ds are not visually affected by Scale.
public Vector3 Scale { get; set; }
Property Value
TopLevel
If true
, the node will not inherit its transformations from its parent. Node transformations are only in global space.
public bool TopLevel { get; set; }
Property Value
Transform
Local space Transform3D of this node, with respect to the parent node.
public Transform3D Transform { get; set; }
Property Value
VisibilityParent
Defines the visibility range parent for this node and its subtree. The visibility parent must be a GeometryInstance3D. Any visual instance will only be visible if the visibility parent (and all of its visibility ancestors) is hidden by being closer to the camera than its own VisibilityRangeBegin. Nodes hidden via the Visible property are essentially removed from the visibility dependency tree, so dependent instances will not take the hidden node or its ancestors into account.
public NodePath VisibilityParent { get; set; }
Property Value
Visible
If true
, this node is drawn. The node is only visible if all of its ancestors are visible as well (in other words, IsVisibleInTree() must return true
).
public bool Visible { get; set; }
Property Value
Methods
AddGizmo(Node3DGizmo)
Attach an editor gizmo to this Node3D.
Note: The gizmo object would typically be an instance of EditorNode3DGizmo
, but the argument type is kept generic to avoid creating a dependency on editor classes in Node3D.
public void AddGizmo(Node3DGizmo gizmo)
Parameters
gizmo
Node3DGizmo
ClearGizmos()
Clear all gizmos attached to this Node3D.
public void ClearGizmos()
ClearSubgizmoSelection()
Clears subgizmo selection for this node in the editor. Useful when subgizmo IDs become invalid after a property change.
public void ClearSubgizmoSelection()
ForceUpdateTransform()
Forces the transform to update. Transform changes in physics are not instant for performance reasons. Transforms are accumulated and then set. Use this if you need an up-to-date transform when doing physics operations.
public void ForceUpdateTransform()
GetGizmos()
Returns all the gizmos attached to this Node3D.
public Array<Node3DGizmo> GetGizmos()
Returns
GetParentNode3D()
Returns the parent Node3D, or null
if no parent exists, the parent is not of type Node3D, or TopLevel is true
.
Note: Calling this method is not equivalent to get_parent() as Node3D
, which does not take TopLevel into account.
public Node3D GetParentNode3D()
Returns
GetWorld3D()
public World3D GetWorld3D()
Returns
GlobalRotate(Vector3, float)
Rotates the global (world) transformation around axis, a unit Vector3, by specified angle in radians. The rotation axis is in global coordinate system.
public void GlobalRotate(Vector3 axis, float angle)
Parameters
GlobalScale(Vector3)
Scales the global (world) transformation by the given Vector3 scale factors.
public void GlobalScale(Vector3 scale)
Parameters
scale
Vector3
GlobalTranslate(Vector3)
Moves the global (world) transformation by Vector3 offset. The offset is in global coordinate system.
public void GlobalTranslate(Vector3 offset)
Parameters
offset
Vector3
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
Hide()
Disables rendering of this node. Changes Visible to false
.
public void Hide()
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsLocalTransformNotificationEnabled()
Returns whether node notifies about its local transformation changes. Node3D will not propagate this by default.
public bool IsLocalTransformNotificationEnabled()
Returns
IsScaleDisabled()
Returns whether this node uses a scale of (1, 1, 1)
or its local transformation scale.
public bool IsScaleDisabled()
Returns
IsTransformNotificationEnabled()
Returns whether the node notifies about its global and local transformation changes. Node3D will not propagate this by default.
public bool IsTransformNotificationEnabled()
Returns
IsVisibleInTree()
Returns true
if the node is present in the SceneTree, its Visible property is true
and all its ancestors are also visible. If any ancestor is hidden, this node will not be visible in the scene tree.
public bool IsVisibleInTree()
Returns
LookAt(Vector3, Vector3?, bool)
Rotates the node so that the local forward axis (-Z, Vector3.FORWARD
) points toward the target
position.
The local up axis (+Y) points as close to the up
vector as possible while staying perpendicular to the local forward axis. The resulting transform is orthogonal, and the scale is preserved. Non-uniform scaling may not work correctly.
The target
position cannot be the same as the node's position, the up
vector cannot be zero, and the direction from the node's position to the target
vector cannot be parallel to the up
vector.
Operations take place in global space, which means that the node must be in the scene tree.
If useModelFront
is true
, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target
position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).
public void LookAt(Vector3 target, Vector3? up = null, bool useModelFront = false)
Parameters
target
Vector3up
Vector3?If the parameter is null, then the default value is
new Vector3(0, 1, 0)
.useModelFront
bool
LookAtFromPosition(Vector3, Vector3, Vector3?, bool)
Moves the node to the specified position
, and then rotates the node to point toward the target
as per LookAt(Vector3, Vector3?, bool). Operations take place in global space.
public void LookAtFromPosition(Vector3 position, Vector3 target, Vector3? up = null, bool useModelFront = false)
Parameters
position
Vector3target
Vector3up
Vector3?If the parameter is null, then the default value is
new Vector3(0, 1, 0)
.useModelFront
bool
Orthonormalize()
Resets this node's transformations (like scale, skew and taper) preserving its rotation and translation by performing Gram-Schmidt orthonormalization on this node's Transform3D.
public void Orthonormalize()
Rotate(Vector3, float)
Rotates the local transformation around axis, a unit Vector3, by specified angle in radians.
public void Rotate(Vector3 axis, float angle)
Parameters
RotateObjectLocal(Vector3, float)
Rotates the local transformation around axis, a unit Vector3, by specified angle in radians. The rotation axis is in object-local coordinate system.
public void RotateObjectLocal(Vector3 axis, float angle)
Parameters
RotateX(float)
Rotates the local transformation around the X axis by angle in radians.
public void RotateX(float angle)
Parameters
angle
float
RotateY(float)
Rotates the local transformation around the Y axis by angle in radians.
public void RotateY(float angle)
Parameters
angle
float
RotateZ(float)
Rotates the local transformation around the Z axis by angle in radians.
public void RotateZ(float angle)
Parameters
angle
float
ScaleObjectLocal(Vector3)
Scales the local transformation by given 3D scale factors in object-local coordinate system.
public void ScaleObjectLocal(Vector3 scale)
Parameters
scale
Vector3
SetDisableScale(bool)
Sets whether the node uses a scale of (1, 1, 1)
or its local transformation scale. Changes to the local transformation scale are preserved.
public void SetDisableScale(bool disable)
Parameters
disable
bool
SetIdentity()
Reset all transformations for this node (sets its Transform3D to the identity matrix).
public void SetIdentity()
SetIgnoreTransformNotification(bool)
Sets whether the node ignores notification that its transformation (global or local) changed.
public void SetIgnoreTransformNotification(bool enabled)
Parameters
enabled
bool
SetNotifyLocalTransform(bool)
Sets whether the node notifies about its local transformation changes. Node3D will not propagate this by default.
public void SetNotifyLocalTransform(bool enable)
Parameters
enable
bool
SetNotifyTransform(bool)
Sets whether the node notifies about its global and local transformation changes. Node3D will not propagate this by default, unless it is in the editor context and it has a valid gizmo.
public void SetNotifyTransform(bool enable)
Parameters
enable
bool
SetSubgizmoSelection(Node3DGizmo, int, Transform3D)
Set subgizmo selection for this node in the editor.
Note: The gizmo object would typically be an instance of EditorNode3DGizmo
, but the argument type is kept generic to avoid creating a dependency on editor classes in Node3D.
public void SetSubgizmoSelection(Node3DGizmo gizmo, int id, Transform3D transform)
Parameters
gizmo
Node3DGizmoid
inttransform
Transform3D
Show()
Enables rendering of this node. Changes Visible to true
.
public void Show()
ToGlobal(Vector3)
Transforms localPoint
from this node's local space to world space.
public Vector3 ToGlobal(Vector3 localPoint)
Parameters
localPoint
Vector3
Returns
ToLocal(Vector3)
Transforms globalPoint
from world space to this node's local space.
public Vector3 ToLocal(Vector3 globalPoint)
Parameters
globalPoint
Vector3
Returns
Translate(Vector3)
Changes the node's position by the given offset Vector3.
Note that the translation offset
is affected by the node's scale, so if scaled by e.g. (10, 1, 1)
, a translation by an offset of (2, 0, 0)
would actually add 20 (2 * 10
) to the X coordinate.
public void Translate(Vector3 offset)
Parameters
offset
Vector3
TranslateObjectLocal(Vector3)
Changes the node's position by the given offset Vector3 in local space.
public void TranslateObjectLocal(Vector3 offset)
Parameters
offset
Vector3
UpdateGizmos()
Updates all the Node3D gizmos attached to this node.
public void UpdateGizmos()
Events
VisibilityChanged
Emitted when node visibility changes.
public event Action VisibilityChanged