Overhaul arrows

This commit is contained in:
oilboi 2020-05-28 04:00:41 -04:00
parent 75f4f21f09
commit 05d0b173db

View File

@ -2,14 +2,14 @@ local arrow = {}
arrow.initial_properties = {
physical = true,
collide_with_objects = false,
collisionbox = {-0.37, -0.4, -0.37, 0.37, 0.5, 0.37},
collisionbox = {-0.05, -0.05, -0.05, 0.05, 0.05, 0.05},
visual = "mesh",
visual_size = {x = 1 , y = 1},
mesh = "basic_bow_arrow.b3d",
textures = {
"basic_bow_arrow_uv.png"
},
pointable = false,
pointable = true,
glow = -1,
--automatic_face_movement_dir = 0.0,
--automatic_face_movement_max_rotation_per_sec = 600,
@ -24,25 +24,15 @@ local radians_to_degrees = function(radians)
end
arrow.spin = 0
arrow.owner = ""
arrow.on_step = function(self, dtime)
arrow.stuck = false
arrow.on_step = function(self, dtime,moveresult)
local pos = self.object:get_pos()
local vel = self.object:get_velocity()
self.spin = self.spin + (dtime*10)
if self.spin > math.pi then
self.spin = -math.pi
end
for _,object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
if (object:is_player() and object:get_hp() > 0 and object:get_player_name() ~= self.thrower) or (object:get_luaentity() and object:get_luaentity().mob == true) then
if object:is_player() and object:get_player_name() ~= self.owner then
object:punch(self.object, 2,
{
full_punch_interval=1.5,
damage_groups = {fleshy=3},
})
hit = true
self.object:remove()
break
elseif not object:is_player() then
if (object:is_player() and object:get_player_name() ~= self.owner) or (object:get_luaentity() and object:get_luaentity().mob == true) then
object:punch(self.object, 2,
{
full_punch_interval=1.5,
@ -54,16 +44,48 @@ arrow.on_step = function(self, dtime)
end
end
end
if (self.oldvel and ((vel.x == 0 and self.oldvel.x ~= 0) or (vel.z == 0 and self.oldvel.z ~= 0) or (vel.y == 0 and self.oldvel.y ~= 0))) then
--self.object:set_velocity(vector.new(0,0,0))
--self.object:set_acceleration(vector.new(0,0,0))
minetest.sound_play("arrow_hit",{object=self.object,gain=1,pitch=math.random(80,100)/100,max_hear_distance=64})
minetest.throw_item(pos, "bow:arrow")
self.object:remove()
end
if pos and self.oldpos then
if moveresult and moveresult.collides and self.stuck == false then
if moveresult.collisions[1].new_velocity.x == 0 and moveresult.collisions[1].old_velocity.x ~= 0 then
self.check_dir = vector.direction(vector.new(pos.x,0,0),vector.new(moveresult.collisions[1].node_pos.x,0,0))
elseif moveresult.collisions[1].new_velocity.y == 0 and moveresult.collisions[1].old_velocity.y ~= 0 then
self.check_dir = vector.direction(vector.new(0,pos.y,0),vector.new(0,moveresult.collisions[1].node_pos.y,0))
elseif moveresult.collisions[1].new_velocity.z == 0 and moveresult.collisions[1].old_velocity.z ~= 0 then
self.check_dir = vector.direction(vector.new(0,0,pos.z),vector.new(0,0,moveresult.collisions[1].node_pos.z))
end
minetest.sound_play("arrow_hit",{object=self.object,gain=1,pitch=math.random(80,100)/100,max_hear_distance=64})
self.stuck = true
self.object:set_velocity(vector.new(0,0,0))
self.object:set_acceleration(vector.new(0,0,0))
elseif self.stuck == true and self.check_dir then
local pos2 = vector.add(pos,vector.multiply(self.check_dir,0.2))
minetest.add_particle({
pos = pos2,
velocity = {x=0, y=0, z=0},
acceleration = {x=0, y=0, z=0},
expirationtime = 0.2,
size = 1,
texture = "dirt.png",
})
local ray = minetest.raycast(pos, pos2, false, false)
local pointed_thing = ray:next()
if not pointed_thing then
self.stuck = false
self.object:set_acceleration(vector.new(0,-9.81,0))
end
end
if not self.stuck and pos and self.oldpos then
self.spin = self.spin + (dtime*10)
if self.spin > math.pi then
self.spin = -math.pi
end
local dir = vector.normalize(vector.subtract(pos,self.oldpos))
local y = minetest.dir_to_yaw(dir)
local x = (minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(self.oldpos.x,0,self.oldpos.z)),0,pos.y-self.oldpos.y))+(math.pi/2))
@ -71,8 +93,10 @@ arrow.on_step = function(self, dtime)
--local frame = self.get_animation_frame(dir)
--self.object:set_animation({x=frame, y=frame}, 0)
end
self.oldpos = pos
self.oldvel = vel
if self.stuck == false then
self.oldpos = pos
self.oldvel = vel
end
end
minetest.register_entity("bow:arrow", arrow)