From 6a1ff8ea00a62bfab75780aa686ea7907b16a019 Mon Sep 17 00:00:00 2001 From: epCode <64379263+epCode@users.noreply.github.com> Date: Mon, 17 Oct 2022 14:22:28 -0700 Subject: [PATCH] make arrows not bounce off nodes and give a wiggle animation when hit --- mods/ITEMS/mcl_bows/arrow.lua | 43 ++++++++++++------ mods/ITEMS/mcl_bows/models/mcl_bows_arrow.b3d | Bin 0 -> 1424 bytes 2 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 mods/ITEMS/mcl_bows/models/mcl_bows_arrow.b3d diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 2181d7b98..04eaa348b 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -59,7 +59,7 @@ local ARROW_ENTITY={ physical = true, pointable = false, visual = "mesh", - mesh = "mcl_bows_arrow.obj", + mesh = "mcl_bows_arrow.b3d", visual_size = {x=-1, y=1}, textures = {"mcl_bows_arrow.png"}, collisionbox = {-0.19, -0.125, -0.19, 0.19, 0.125, 0.19}, @@ -132,6 +132,9 @@ function ARROW_ENTITY.on_step(self, dtime) self.object:remove() return end + if self._stuck_pos and self.object:get_pos() ~= self._stuck_pos then + self.object:set_pos(self._stuck_pos) + end -- Drop arrow as item when it is no longer stuck -- FIXME: Arrows are a bit slow to react and continue to float in mid air for a few seconds. if self._stuckrechecktimer > STUCK_RECHECK_TIME then @@ -172,7 +175,7 @@ function ARROW_ENTITY.on_step(self, dtime) if self._damage >= 9 and self._in_player == false then minetest.add_particlespawner({ amount = 20, - time = .2, + time = .1, minpos = vector.new(0,0,0), maxpos = vector.new(0,0,0), minvel = vector.new(-0.1,-0.1,-0.1), @@ -198,7 +201,7 @@ function ARROW_ENTITY.on_step(self, dtime) local arrow_dir = self.object:get_velocity() --create a raycast from the arrow based on the velocity of the arrow to deal with lag - local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.1)), true, false) + local raycast = minetest.raycast(vector.add(pos, vector.multiply(arrow_dir, -0.03)), vector.add(pos, vector.multiply(arrow_dir, 0.1)), true, false) for hitpoint in raycast do if hitpoint.type == "object" then -- find the closest object that is in the way of the arrow @@ -220,6 +223,11 @@ function ARROW_ENTITY.on_step(self, dtime) closest_distance = dist end end + elseif hitpoint.type == "node" then + if not self._stuck and minetest.registered_nodes[minetest.get_node(hitpoint.under).name].walkable then + self._stuck_pos = hitpoint.intersection_point + self._stuckin = hitpoint.under + end end end @@ -351,25 +359,27 @@ function ARROW_ENTITY.on_step(self, dtime) local vel = self.object:get_velocity() -- Arrow has stopped in one axis, so it probably hit something. -- This detection is a bit clunky, but sadly, MT does not offer a direct collision detection for us. :-( - if (math.abs(vel.x) < 0.0001) or (math.abs(vel.z) < 0.0001) or (math.abs(vel.y) < 0.00001) then + if (math.abs(vel.x) < 0.0001) or (math.abs(vel.z) < 0.0001) or (math.abs(vel.y) < 0.00001) or self._stuck_pos then -- Check for the node to which the arrow is pointing - local dir - if math.abs(vel.y) < 0.00001 then - if self._lastpos.y < pos.y then - dir = vector.new(0, 1, 0) + if not self._stuck_pos then + local dir + if math.abs(vel.y) < 0.00001 then + if self._lastpos.y < pos.y then + dir = vector.new(0, 1, 0) + else + dir = vector.new(0, -1, 0) + end else - dir = vector.new(0, -1, 0) + dir = minetest.facedir_to_dir(minetest.dir_to_facedir(minetest.yaw_to_dir(self.object:get_yaw()-YAW_OFFSET))) end - else - dir = minetest.facedir_to_dir(minetest.dir_to_facedir(minetest.yaw_to_dir(self.object:get_yaw()-YAW_OFFSET))) + self._stuckin = vector.add(dpos, dir) end - self._stuckin = vector.add(dpos, dir) local snode = minetest.get_node(self._stuckin) local sdef = minetest.registered_nodes[snode.name] -- If node is non-walkable, unknown or ignore, don't make arrow stuck. -- This causes a deflection in the engine. - if not sdef or sdef.walkable == false or snode.name == "ignore" then + if (not sdef or sdef.walkable == false or snode.name == "ignore") and not self._stuck_pos then self._stuckin = nil if self._deflection_cooloff <= 0 then -- Lose 1/3 of velocity on deflection @@ -380,7 +390,6 @@ function ARROW_ENTITY.on_step(self, dtime) self._deflection_cooloff = 1.0 end else - -- Node was walkable, make arrow stuck self._stuck = true self._stucktimer = 0 @@ -389,8 +398,14 @@ function ARROW_ENTITY.on_step(self, dtime) self.object:set_velocity(vector.new(0, 0, 0)) self.object:set_acceleration(vector.new(0, 0, 0)) + if self._stuck_pos then + self.object:set_pos(self._stuck_pos) + end + minetest.sound_play({name="mcl_bows_hit_other", gain=0.3}, {pos=self.object:get_pos(), max_hear_distance=16}, true) + self.object:set_animation({x=1,y=20}, 50, 0, false) + if mcl_burning.is_burning(self.object) and snode.name == "mcl_tnt:tnt" then tnt.ignite(self._stuckin) end diff --git a/mods/ITEMS/mcl_bows/models/mcl_bows_arrow.b3d b/mods/ITEMS/mcl_bows/models/mcl_bows_arrow.b3d new file mode 100644 index 0000000000000000000000000000000000000000..b4c75d99e8fdb65f92b8d5461a560dba462395f0 GIT binary patch literal 1424 zcmZ`%TS!zv7(R9}%}c4!{b*E>kccKxAnYM8dgvi2 zf-YznTDmF-xt-aPH6JoDNa*rZ4++tekw%vN-|iebL_6^F&wTU!GvD{mSgl#M&XtN1 zp(u*gS?uGT~m5S#%^WuWf3<*Q9PXXgCyi78jcd1J(mtCZK^xf0MInR zHpkzsV!JCpZCU7q3TK(?HtwZ?M6hx+*6q)FtMU9rjqlxX;>p6RR8~)z)~1P*wVD9t zsg3m!&jPH9upi$R7%<{lPSeE_K1(FkR?42Dw#-@JI*$jUf%lQmr7V|g;E@#c5tJ1atK=H<)fCYb zQ4}$9jd?sp97Qa}8o9g$3|| z%IkZ6FSYR{3Vgug8ZVoeQh8uX6}B3$ZY^=x?}8W{9v(8|;V=e1Od&%&GE5=EATrD$ z!vr$SA%{eHI80(466@hGi8Tx(!z?mPA;T;(j3dJ|a-qH2HA~`fA2f#Z=OBMC$lo~m zvy(sgFmr#&KH$um^ltXFG=~4|P8WqeqdL5rxklg6yL0YA)^}kOpPt()I(i0l^y7bA zoI8F*XYH3#c|vre`0VP^(X((|+x8K5=)q>be>O#oX}vo78jgF@>1D6;RX$vmEXu3B zI(lK|LZ|W0ms@*T#HVC_YiNteP9D+mK4z}r4SE~ZVRmI+