1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
epCode d36939d2df add sound and other fixes 2022-10-17 15:11:36 -07:00
epCode 6a1ff8ea00 make arrows not bounce off nodes and give a wiggle animation when hit 2022-10-17 14:22:28 -07:00
3 changed files with 30 additions and 14 deletions

View File

@ -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 and self._time_in_air > 1.4 then
self._stuck_pos = hitpoint.intersection_point
self._stuckin = hitpoint.under
end
end
end
@ -351,8 +359,9 @@ 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
if not self._stuck_pos then
local dir
if math.abs(vel.y) < 0.00001 then
if self._lastpos.y < pos.y then
@ -364,12 +373,13 @@ function ARROW_ENTITY.on_step(self, dtime)
dir = minetest.facedir_to_dir(minetest.dir_to_facedir(minetest.yaw_to_dir(self.object:get_yaw()-YAW_OFFSET)))
end
self._stuckin = vector.add(dpos, dir)
end
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,7 +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)
minetest.sound_play({name="mcl_bows_hit_wiggle", gain=0.3}, {pos=self.object:get_pos(), max_hear_distance=9}, 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)

Binary file not shown.

Binary file not shown.