Skip to main content

Node2D

Inherits: CanvasItem < Node < Object

Description

A 2D game object with a transform (position, rotation, and scale). All 2D nodes, including physics objects and sprites, inherit from Node2D.

Properties

position
Vector2
default:"Vector2(0, 0)"
Position, relative to the node’s parent.
rotation
float
default:"0.0"
Rotation in radians, relative to the node’s parent.
scale
Vector2
default:"Vector2(1, 1)"
The node’s scale. Unscaled value: (1, 1).
global_position
Vector2
Global position. See also position.

Methods

rotate

void rotate(radians: float)
Applies a rotation to the node, in radians.

translate

void translate(offset: Vector2)
Translates the node by the given offset in local coordinates.

look_at

void look_at(point: Vector2)
Rotates the node so that its local +X axis points towards the point.

get_angle_to

float get_angle_to(point: Vector2)
Returns the angle between the node and the point in radians.

Example Usage

var sprite = Node2D.new()
sprite.position = Vector2(100, 200)
sprite.rotation = deg_to_rad(45)
sprite.scale = Vector2(2, 2)

# Rotate the node
sprite.rotate(deg_to_rad(90))

# Look at a point
sprite.look_at(Vector2(500, 300))

Build docs developers (and LLMs) love