Skip to content

Latest commit

 

History

History
62 lines (45 loc) · 1.18 KB

vector2.md

File metadata and controls

62 lines (45 loc) · 1.18 KB

shard.vector2

Vector2 class

Features

  • Lots of helper methods
  • Chaining methods
  • Defined methods for +, -, *, /, ==, ~= operators
  • Defined tostring method
local Vector2 = require("shard.vector2")

Vector2:new(x, y)

Creates new vector

Vector2:set(x, y)

Sets vector

Vector2:copy()

Copies vector

Vector2:add(vectorOrNumber)

Adds vector / number to current vector

Vector2:subtract(vectorOrNumber)

Subrects vector / number to current vector

Vector2:multiply(vectorOrNumber)

Multiplies vector / number to current vector

Vector2:divide(vectorOrNumber)

Divides vector / number to current vector

Vector2:normalize()

Normalizes vector

Vector2:length()

Returns vector length

Vector2:setLength(length)

Sets vector length

Vector2:distance(vector)

Returns distance to another vector

Vector2:lerp(destVector, progress)

Lerps current vector to destVector by progress (0 - 1)

Vector2:rotateRad(radians)

Rotates vector using radians

Example

local Vector2 = require("shard/vector2")

local direction = Vector2(1, 0)
direction:rotateRad(1):add(5)
direction = direction - Vector2(0.365, 5):length()
direction:setLength(2.25)
print(direction)