Missile rotation

The missiles rotate depending of if they are fired up or down.
Currently does not work when moving straight ahead, ie: it will point
either up or down
master
D00Med 2016-10-21 05:54:41 +10:00
parent b6af0344ca
commit 6632735116
4 changed files with 26 additions and 2 deletions

14
api.lua
View File

@ -362,6 +362,11 @@ function object_fly(entity, dtime, speed, accel, decell, shoots, arrow, moving_a
entity.object:setvelocity(vec_stop)
entity.object:setacceleration({x=0, y=-4.5, z=0})
end
if ctrl.jump and ctrl.up then
entity.object:setvelocity({x=dir.x*speed, y=0, z=dir.z*speed})
elseif ctrl.jump and not ctrl.up then
entity.object:setvelocity({x=velo.x*decell, y=0, z=velo.z*decell})
end
if ctrl.sneak and shoots and entity.loaded then
entity.loaded = false
local pos = entity.object:getpos()
@ -679,10 +684,19 @@ minetest.register_tool(vehicle.."_spawner", {
})
end
--out of date, left behind in case it is needed again
function vehicle_drop(ent, player, name)
if ent.owner == player then
local pos = ent.object:getpos()
minetest.env:add_item(pos, name.."_spawner")
ent.object:remove()
end
end
function destroy(ent, player, name)
if ent.object:get_hp() == 0 and ent.owner == player then
local pos = ent.object:getpos()
minetest.env:add_item(pos, "vehicles:tank_spawner")
end
end

View File

@ -94,6 +94,14 @@ minetest.register_entity("vehicles:missile_2", {
minetest.after(10, function()
self.object:remove()
end)
local velo = self.object:getvelocity()
if velo.y <= 1 and velo.y >= -1 then
self.object:set_animation({x=1, y=1}, 5, 0)
elseif velo.y <= -1 then
self.object:set_animation({x=4, y=4}, 5, 0)
elseif velo.y >= 1 then
self.object:set_animation({x=2, y=2}, 5, 0)
end
local pos = self.object:getpos()
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
@ -212,6 +220,7 @@ minetest.register_entity("vehicles:tank", {
textures = {"vehicles_tank.png"},
velocity = 15,
acceleration = -5,
owner = "",
stepheight = 1.5,
hp_max = 200,
physical = true,
@ -224,7 +233,7 @@ minetest.register_entity("vehicles:tank", {
end
end,
on_punch = function(self, puncher)
vehicle_drop(self, puncher, "vehicles:tank")
destroy(self, puncher, "vehicles:tank")
end,
on_step = function(self, dtime)
if self.driver then
@ -242,7 +251,8 @@ minetest.register_entity("vehicles:turret", {
velocity = 15,
acceleration = -5,
stepheight = 1.5,
hp_max = 200,
hp_max = 50,
groups = {fleshy=3, level=5},
physical = true,
collisionbox = {-0.6, 0, -0.6, 0.6, 0.9, 0.6},
on_rightclick = function(self, clicker)

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB