struct Godot::Vector2

Overview

2-element structure that can be used to represent 2D coordinates or vectors with 32-bit floating point precision.

Defined in:

libgodot/types.cr

Constant Summary

DOWN = Vector2.new(0.0_f32, 1.0_f32)
INF = Vector2.new(Float32::INFINITY, Float32::INFINITY)
LEFT = Vector2.new(-1.0_f32, 0.0_f32)
ONE = Vector2.new(1.0_f32, 1.0_f32)
RIGHT = Vector2.new(1.0_f32, 0.0_f32)
UP = Vector2.new(0.0_f32, -1.0_f32)
ZERO = Vector2.new(0.0_f32, 0.0_f32)

Constructors

Instance Method Summary

Constructor Detail

def self.new(x : Float32 = 0.0_f32, y : Float32 = 0.0_f32) #

[View source]
def self.new(x : Number, y : Number) #

[View source]

Instance Method Detail

def *(scalar : Number) : Vector2 #

[View source]
def *(other : Vector2) : Vector2 #

[View source]
def +(other : Vector2) : Vector2 #

[View source]
def -(other : Vector2) : Vector2 #

[View source]
def - : Vector2 #

[View source]
def /(scalar : Number) : Vector2 #

[View source]
def /(other : Vector2) : Vector2 #

[View source]
def abs : Vector2 #

[View source]
def angle : Float32 #

Returns the angle in radians of this vector with respect to the positive X-axis.


[View source]
def angle_to(to : Vector2) : Float32 #

Returns the unsigned angle in radians between this vector and other.


[View source]
def angle_to_point(to : Vector2) : Float32 #

Returns the angle in radians between this vector and the given point.


[View source]
def aspect : Float32 #

[View source]
def bounce(normal : Vector2) : Vector2 #

Returns a new vector bounced off a plane defined by the given normal.


[View source]
def ceil : Vector2 #

[View source]
def clamp(min : Vector2, max : Vector2) : Vector2 #

Clamps each component between min and max.


[View source]
def cross(other : Vector2) : Float32 #

[View source]
def direction_to(other : Vector2) : Vector2 #

Returns the normalized direction from this vector toward other.


[View source]
def distance_squared_to(other : Vector2) : Float32 #

Returns the squared distance between this vector and other.


[View source]
def distance_to(other : Vector2) : Float32 #

Returns the distance between this vector and other.


[View source]
def dot(other : Vector2) : Float32 #

[View source]
def floor : Vector2 #

[View source]
def is_equal_approx(other : Vector2) : Bool #

[View source]
def is_normalized? : Bool #

[View source]
def is_zero_approx : Bool #

[View source]
def length : Float32 #

[View source]
def length_squared : Float32 #

[View source]
def lerp(to : Vector2, weight : Number) : Vector2 #

Linearly interpolates between this vector and to by weight.


[View source]
def limit_length(max_length : Number = 1.0) : Vector2 #

Clamps the vector's length to max_length.


[View source]
def max(other : Vector2) : Vector2 #

[View source]
def min(other : Vector2) : Vector2 #

[View source]
def move_toward(to : Vector2, delta : Number) : Vector2 #

Moves this vector toward to by the given delta amount, never exceeding to.


[View source]
def normalized : Vector2 #

[View source]
def orthogonal : Vector2 #

Returns the vector rotated 90 degrees counter-clockwise.


[View source]
def perpendicular : Vector2 #

Alias for orthogonal.


[View source]
def project(b : Vector2) : Vector2 #

Projects this vector onto vector b.


[View source]
def reflect(normal : Vector2) : Vector2 #

Returns a new vector reflected from a plane defined by the given normal.


[View source]
def rotated(angle : Number) : Vector2 #

Rotates this vector by the given angle in radians.


[View source]
def round : Vector2 #

[View source]
def sign : Vector2 #

[View source]
def slerp(to : Vector2, weight : Number) : Vector2 #

Spherically interpolates between this vector and to by weight.


[View source]
def slide(normal : Vector2) : Vector2 #

Returns a new vector slid along a plane defined by the given normal.


[View source]
def to_i : Vector2i #

[View source]
def to_s(io : IO) : Void #
Description copied from struct Struct

Same as #inspect(io).


[View source]
def x : Float32 #

[View source]
def x=(x : Float32) #

[View source]
def y : Float32 #

[View source]
def y=(y : Float32) #

[View source]