fix angle rounding and tweak formulas

This commit is contained in:
whosit 2021-05-23 02:01:24 +03:00
parent 1184f125ad
commit 2f25cd5bfd

View File

@ -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)