Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Vector2

A 2D vector using floating point coordinates.

Description

A 2-element structure that can be used to represent 2D coordinates or any other pair of numeric values.

It uses floating-point coordinates. By default, these floating-point values use 32-bit precision, unlike float which is always 64-bit. If double precision is needed, compile the engine with the option precision=double.

See Vector2i for its integer counterpart.

Note: In a boolean context, a Vector2 will evaluate to false if it's equal to Vector2(0, 0). Otherwise, a Vector2 will always evaluate to true.

Tutorials

Properties

float

x

0.0

float

y

0.0

Constructors

Vector2

Vector2()

Vector2

Vector2(from: Vector2)

Vector2

Vector2(from: Vector2i)

Vector2

Vector2(x: float, y: float)

Methods

Vector2

abs() const

float

angle() const

float

angle_to(to: Vector2) const

float

angle_to_point(to: Vector2) const

float

aspect() const

Vector2

bezier_derivative(control_1: Vector2, control_2: Vector2, end: Vector2, t: float) const

Vector2

bezier_interpolate(control_1: Vector2, control_2: Vector2, end: Vector2, t: float) const

Vector2

bounce(n: Vector2) const

Vector2

ceil() const

Vector2

clamp(min: Vector2, max: Vector2) const

float

cross(with: Vector2) const

Vector2

cubic_interpolate(b: Vector2, pre_a: Vector2, post_b: Vector2, weight: float) const

Vector2

cubic_interpolate_in_time(b: Vector2, pre_a: Vector2, post_b: Vector2, weight: float, b_t: float, pre_a_t: float, post_b_t: float) const

Vector2

direction_to(to: Vector2) const

float

distance_squared_to(to: Vector2) const

float

distance_to(to: Vector2) const

float

dot(with: Vector2) const

Vector2

floor() const

Vector2

from_angle(angle: float) static

bool

is_equal_approx(to: Vector2) const

bool

is_finite() const

bool

is_normalized() const

bool

is_zero