util.math.rotation_2d
Shared
Calculates the angle from one 2D point to another, in degrees
Syntax
local result = util.math.rotation_2d(
a,
b
)Parameters
| Type | Name | Description |
|---|---|---|
vector2 | a | Origin point |
vector2 | b | Target point |
Returns
| Type | Name | Description |
|---|---|---|
float | result | Angle from a to b in degrees, normalized to the range 0-360 |
Examples
local result = util.math.rotation_2d({0, 0}, {10, 0})
core.engine.print("info", result) -- 0.0local result = util.math.rotation_2d({0, 0}, {0, 10})
core.engine.print("info", result) -- 90.0local result = util.math.rotation_2d({0, 0}, {0, -10})
core.engine.print("info", result) -- 270.0 (not -90.0)local result = util.math.rotation_2d({0, 0}, {10, 10})
core.engine.print("info", result) -- 45.0local entity_pos = {100, 100}
local target_pos = {200, 50}
local facing_angle = util.math.rotation_2d(entity_pos, target_pos)
core.engine.print("info", facing_angle) -- 333.43494...