Rework throwing code, add egg
This commit is contained in:
parent
e85a830a01
commit
b6575ab192
30 changed files with 142 additions and 139 deletions
|
@ -658,50 +658,6 @@ minetest.register_abm({
|
|||
})
|
||||
|
||||
|
||||
--
|
||||
-- Snowballs
|
||||
--
|
||||
|
||||
snowball_GRAVITY=9
|
||||
snowball_VELOCITY=19
|
||||
|
||||
--Shoot snowball.
|
||||
snow_shoot_snowball=function (item, player, pointed_thing)
|
||||
local playerpos=player:getpos()
|
||||
local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "default:snowball_entity")
|
||||
local dir=player:get_look_dir()
|
||||
obj:setvelocity({x=dir.x*snowball_VELOCITY, y=dir.y*snowball_VELOCITY, z=dir.z*snowball_VELOCITY})
|
||||
obj:setacceleration({x=dir.x*-3, y=-snowball_GRAVITY, z=dir.z*-3})
|
||||
item:take_item()
|
||||
return item
|
||||
end
|
||||
|
||||
--The snowball Entity
|
||||
snowball_ENTITY={
|
||||
physical = false,
|
||||
timer=0,
|
||||
textures = {"default_snowball.png"},
|
||||
lastpos={},
|
||||
collisionbox = {0,0,0,0,0,0},
|
||||
}
|
||||
|
||||
--Snowball_entity.on_step()--> called when snowball is moving.
|
||||
snowball_ENTITY.on_step = function(self, dtime)
|
||||
self.timer=self.timer+dtime
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
--Become item when hitting a node.
|
||||
if self.lastpos.x~=nil then --If there is no lastpos for some reason.
|
||||
if node.name ~= "air" then
|
||||
self.object:remove()
|
||||
end
|
||||
end
|
||||
self.lastpos={x=pos.x, y=pos.y, z=pos.z} -- Set lastpos-->Node will be added at last pos outside the node
|
||||
end
|
||||
|
||||
minetest.register_entity("default:snowball_entity", snowball_ENTITY)
|
||||
|
||||
-- Global environment step function
|
||||
function on_step(dtime)
|
||||
-- print("on_step")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue