From 2f25cd5bfd0974ec002458fa8176f4c6f846f89b Mon Sep 17 00:00:00 2001 From: whosit Date: Sun, 23 May 2021 02:01:24 +0300 Subject: [PATCH] fix angle rounding and tweak formulas --- init.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index 4566821..ed123c0 100644 --- a/init.lua +++ b/init.lua @@ -93,11 +93,13 @@ local function show_hud_waypoint(player, point_pos, name, icon_name) local v = vector.subtract(point_pos, player:get_pos()) -- angle relative to player position local angle = math.atan2(v.x, v.z) + local pi = math.pi -- snap/round to increments and convert to degrees - local angle_quad = math.floor(angle/(2*math.pi) * 4) * (360 / 4) % 360 + local bias = 1/angle_steps/2 -- add bias to floor into correct quardant + local angle_quad = math.floor(angle/(2*pi) * 4 + bias) * (360 / 4) % 360 local angle_quad_map = {[0] = "I", [90] = "R270", [180] = "R180", [270] = "R90"} - local angle_snap = round(angle/(2*math.pi) * angle_steps * 4) * (360 / (angle_steps * 4)) % 360 - local angle_quad_step = (angle_snap - angle_quad) % 90 + local step_size = 90/angle_steps + local angle_quad_step = (round((math.deg(angle) - angle_quad)/step_size) * step_size) % 90 local arrow_texture = ("arrow_%03d.png"):format(angle_quad_step)