From fdb7d5bfadc80cc3a9fe77b138d3e831cafa50b3 Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Mon, 6 Jun 2022 14:32:07 -0700 Subject: [PATCH] fixed Badly calculated arrow direction --- mods/ITEMS/mcl_bows/arrow.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index d0af738a11..cd32f53920 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -197,8 +197,8 @@ function ARROW_ENTITY.on_step(self, dtime) self._deflection_cooloff = self._deflection_cooloff - dtime end - local arrow_dir = vector.rotate(vector.new(0,0,1), self.object:get_rotation()) - local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 6)), true, false) + local arrow_dir = self.object:get_velocity() + local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.2)), true, false) for hitpoint in raycast do if hitpoint.type == "object" then local ok = false @@ -211,8 +211,13 @@ function ARROW_ENTITY.on_step(self, dtime) end if ok then local dist = vector.distance(hitpoint.ref:get_pos(), pos) - closest_object = hitpoint.ref - closest_distance = dist + if not closest_object or not closest_distance then + closest_object = hitpoint.ref + closest_distance = dist + elseif dist < closest_distance then + closest_object = hitpoint.ref + closest_distance = dist + end end end end