forked from VoxeLibre/VoxeLibre
Compare commits
2 Commits
master
...
arrow_node
Author | SHA1 | Date |
---|---|---|
epCode | d36939d2df | |
epCode | 6a1ff8ea00 |
|
@ -59,7 +59,7 @@ local ARROW_ENTITY={
|
||||||
physical = true,
|
physical = true,
|
||||||
pointable = false,
|
pointable = false,
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
mesh = "mcl_bows_arrow.obj",
|
mesh = "mcl_bows_arrow.b3d",
|
||||||
visual_size = {x=-1, y=1},
|
visual_size = {x=-1, y=1},
|
||||||
textures = {"mcl_bows_arrow.png"},
|
textures = {"mcl_bows_arrow.png"},
|
||||||
collisionbox = {-0.19, -0.125, -0.19, 0.19, 0.125, 0.19},
|
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()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
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
|
-- 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.
|
-- 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
|
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
|
if self._damage >= 9 and self._in_player == false then
|
||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount = 20,
|
amount = 20,
|
||||||
time = .2,
|
time = .1,
|
||||||
minpos = vector.new(0,0,0),
|
minpos = vector.new(0,0,0),
|
||||||
maxpos = vector.new(0,0,0),
|
maxpos = vector.new(0,0,0),
|
||||||
minvel = vector.new(-0.1,-0.1,-0.1),
|
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()
|
local arrow_dir = self.object:get_velocity()
|
||||||
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
--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
|
for hitpoint in raycast do
|
||||||
if hitpoint.type == "object" then
|
if hitpoint.type == "object" then
|
||||||
-- find the closest object that is in the way of the arrow
|
-- 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
|
closest_distance = dist
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -351,8 +359,9 @@ function ARROW_ENTITY.on_step(self, dtime)
|
||||||
local vel = self.object:get_velocity()
|
local vel = self.object:get_velocity()
|
||||||
-- Arrow has stopped in one axis, so it probably hit something.
|
-- 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. :-(
|
-- 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
|
-- Check for the node to which the arrow is pointing
|
||||||
|
if not self._stuck_pos then
|
||||||
local dir
|
local dir
|
||||||
if math.abs(vel.y) < 0.00001 then
|
if math.abs(vel.y) < 0.00001 then
|
||||||
if self._lastpos.y < pos.y 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)))
|
dir = minetest.facedir_to_dir(minetest.dir_to_facedir(minetest.yaw_to_dir(self.object:get_yaw()-YAW_OFFSET)))
|
||||||
end
|
end
|
||||||
self._stuckin = vector.add(dpos, dir)
|
self._stuckin = vector.add(dpos, dir)
|
||||||
|
end
|
||||||
local snode = minetest.get_node(self._stuckin)
|
local snode = minetest.get_node(self._stuckin)
|
||||||
local sdef = minetest.registered_nodes[snode.name]
|
local sdef = minetest.registered_nodes[snode.name]
|
||||||
|
|
||||||
-- If node is non-walkable, unknown or ignore, don't make arrow stuck.
|
-- If node is non-walkable, unknown or ignore, don't make arrow stuck.
|
||||||
-- This causes a deflection in the engine.
|
-- 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
|
self._stuckin = nil
|
||||||
if self._deflection_cooloff <= 0 then
|
if self._deflection_cooloff <= 0 then
|
||||||
-- Lose 1/3 of velocity on deflection
|
-- Lose 1/3 of velocity on deflection
|
||||||
|
@ -380,7 +390,6 @@ function ARROW_ENTITY.on_step(self, dtime)
|
||||||
self._deflection_cooloff = 1.0
|
self._deflection_cooloff = 1.0
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
||||||
-- Node was walkable, make arrow stuck
|
-- Node was walkable, make arrow stuck
|
||||||
self._stuck = true
|
self._stuck = true
|
||||||
self._stucktimer = 0
|
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_velocity(vector.new(0, 0, 0))
|
||||||
self.object:set_acceleration(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_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
|
if mcl_burning.is_burning(self.object) and snode.name == "mcl_tnt:tnt" then
|
||||||
tnt.ignite(self._stuckin)
|
tnt.ignite(self._stuckin)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue