make notplayer react a bit better near stay away objects

This commit is contained in:
bgkillas 2024-10-30 11:55:19 -04:00
parent 51ed3e28ea
commit 2026bf2340

View file

@ -770,6 +770,7 @@ local function choose_movement()
end end
end end
local closest = {500 * 500, 500, 500}
for i = #state.stay_away, 1, -1 do for i = #state.stay_away, 1, -1 do
local pos = state.stay_away[i] local pos = state.stay_away[i]
local x, y = pos[1], pos[2] local x, y = pos[1], pos[2]
@ -779,23 +780,28 @@ local function choose_movement()
else else
local pdx, pdy = x - my_x, y - my_y local pdx, pdy = x - my_x, y - my_y
local r = pdx * pdx + pdy * pdy local r = pdx * pdx + pdy * pdy
if r <= 64 * 64 then if r < closest[1] then
if pdx < 0 then closest = {r, pdx, pdy}
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
end end
end 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 ComponentGetValue2(state.damage_model, "mLiquidCount") == 0 then
if state.dtype == 32 or material_gas > GameGetFrameNum() then if state.dtype == 32 or material_gas > GameGetFrameNum() then