From 2026bf234048b5156d442b482227bc20209a387f Mon Sep 17 00:00:00 2001 From: bgkillas Date: Wed, 30 Oct 2024 11:55:19 -0400 Subject: [PATCH] make notplayer react a bit better near stay away objects --- .../system/notplayer_ai/notplayer_ai.lua | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/quant.ew/files/system/notplayer_ai/notplayer_ai.lua b/quant.ew/files/system/notplayer_ai/notplayer_ai.lua index 72a5378b..a608afa4 100644 --- a/quant.ew/files/system/notplayer_ai/notplayer_ai.lua +++ b/quant.ew/files/system/notplayer_ai/notplayer_ai.lua @@ -770,6 +770,7 @@ local function choose_movement() end end + local closest = {500 * 500, 500, 500} for i = #state.stay_away, 1, -1 do local pos = state.stay_away[i] local x, y = pos[1], pos[2] @@ -779,23 +780,28 @@ local function choose_movement() else local pdx, pdy = x - my_x, y - my_y local r = pdx * pdx + pdy * pdy - if r <= 64 * 64 then - if pdx < 0 then - state.control_d = true - state.control_a = false - else - state.control_a = true - state.control_d = false - end - if pdy < 0 then - state.control_w = false - else - state.control_w = true - end - break + if r < closest[1] then + closest = {r, pdx, pdy} end end end + local pdx, pdy = closest[2], closest[3] + GamePrint(pdx) + GamePrint(pdy) + if math.abs(pdy) < 60 and math.abs(pdx) < 55 then + if pdx < 0 then + state.control_d = true + state.control_a = false + else + state.control_a = true + state.control_d = false + end + if pdy < 0 then + state.control_w = false + else + state.control_w = true + end + end if ComponentGetValue2(state.damage_model, "mLiquidCount") == 0 then if state.dtype == 32 or material_gas > GameGetFrameNum() then