spears/functions.lua

16 lines
579 B
Lua
Raw Normal View History

2015-10-03 20:45:32 +02:00
function spears_shot (itemstack, player)
local spear = itemstack:get_name() .. '_entity'
local playerpos = player:getpos()
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, spear)
local dir = player:get_look_dir()
2015-10-13 22:04:14 +02:00
local sp = 14
local dr = .3
local gravity = 9.8
2015-10-13 21:44:45 +02:00
obj:setvelocity({x=dir.x*sp, y=dir.y*sp, z=dir.z*sp})
obj:setacceleration({x=-dir.x*dr, y=-gravity, z=-dir.z*dr})
2015-10-03 20:45:32 +02:00
obj:setyaw(player:get_look_yaw()+math.pi)
minetest.sound_play("spears_sound", {pos=playerpos})
obj:get_luaentity().wear = itemstack:get_wear()
return true
end