fixed Badly calculated arrow direction

This commit is contained in:
epCode 2022-06-06 14:32:07 -07:00
parent f2c2f4106b
commit fdb7d5bfad
1 changed files with 9 additions and 4 deletions

View File

@ -197,8 +197,8 @@ function ARROW_ENTITY.on_step(self, dtime)
self._deflection_cooloff = self._deflection_cooloff - dtime self._deflection_cooloff = self._deflection_cooloff - dtime
end end
local arrow_dir = vector.rotate(vector.new(0,0,1), self.object:get_rotation()) local arrow_dir = self.object:get_velocity()
local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 6)), true, false) local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.2)), true, false)
for hitpoint in raycast do for hitpoint in raycast do
if hitpoint.type == "object" then if hitpoint.type == "object" then
local ok = false local ok = false
@ -211,8 +211,13 @@ function ARROW_ENTITY.on_step(self, dtime)
end end
if ok then if ok then
local dist = vector.distance(hitpoint.ref:get_pos(), pos) local dist = vector.distance(hitpoint.ref:get_pos(), pos)
closest_object = hitpoint.ref if not closest_object or not closest_distance then
closest_distance = dist closest_object = hitpoint.ref
closest_distance = dist
elseif dist < closest_distance then
closest_object = hitpoint.ref
closest_distance = dist
end
end end
end end
end end