-
Notifications
You must be signed in to change notification settings - Fork 18
Vector 2
The vector2
(vec2) class is a fundamental component for representing and manipulating 2D coordinates. It's extensively used for various calculations and graphical representations in the game.
vec2(x, y)
-
x
: Number - The x-coordinate of the vector. -
y
: Number - The y-coordinate of the vector.
Note
Initializes a new vec2
object with the specified x and y coordinates, essential for 2D spatial operations.
-
.x
: Returns the x-coordinate (Number). -
.y
: Returns the y-coordinate (Number).
is_zero()
-> Boolean
Determines if the vector represents a zero vector (both x and y are zero).
project_3d()
-> vec3
Projects the 2D vector into a 3D space, creating a
vec3
object.
distance(other)
-> Number
-
other
:vec2
- Another vector to measure distance to.
Calculates the Euclidean distance to another
vec2
.
distance_squared(other)
-> Number
-
other
:vec2
- The other vector.
Returns the squared distance to another
vec2
, useful for performance-sensitive calculations.
intersects()
-> Boolean
Evaluates if this vector intersects with another object or vector.
length()
-> Number
Computes the length (magnitude) of the vector.
dot_product(other)
-> Number
-
other
:vec2
- The vector to dot with.
Calculates the dot product with another
vec2
.
get_unit_vector()
-> vec2
Returns the normalized unit vector of this vector.
get_angle(point, origin)
-> Number
Determines the angle to a point from an origin.
get_extended(target, dist)
-> vec2
-
target
:vec2
- The target vector. -
dist
: Number - Distance to extend.
Extends the vector towards a target by the specified distance.
screen_to_coordinate()
-> vec2
Converts screen coordinates to corresponding game coordinates.
coordinate_to_screen()
-> vec2
Translates game coordinates to screen coordinates.
rotate_around(origin, degree)
-> vec2
-
origin
:vec2
- The pivot point for rotation. -
degree
: Number - The angle in degrees for rotation.
Rotates this vector around a specified origin by a given degree.
equals(other)
-> Boolean
-
other
:vec2
- The vector to compare with.
Evaluates if this vector is equal to another
vec2
.