Attrito pt. 1
parent
39ff103f82
commit
60a1742589
|
@ -45,16 +45,18 @@ function quake.register_bullet(name, def)
|
|||
-- nella creazione del proiettile e lo usa alla distruzione. Comodo perchè così è astratta anche quella
|
||||
function bulletentity:_destroy()
|
||||
|
||||
if self.initial_properties.def.on_destroy then
|
||||
self.initial_properties.def.on_destroy(self)
|
||||
spawn_particles_sphere(self.object:get_pos(), self.initial_properties.explosion_texture)
|
||||
|
||||
if self.initial_properties.on_destroy then
|
||||
self.initial_properties.on_destroy(self)
|
||||
end
|
||||
|
||||
-- spawna le particelle
|
||||
spawn_particles_sphere(self.object:get_pos(), self.initial_properties.explosion_texture)
|
||||
self.object:remove()
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
function bulletentity:get_staticdata(self)
|
||||
if self == nil or self.p_name == nil then return end
|
||||
return self.p_name
|
||||
|
@ -196,7 +198,7 @@ end
|
|||
|
||||
--aggiunge le particelle dell'esplosione
|
||||
function spawn_particles_sphere(pos, particle_texture)
|
||||
|
||||
if not pos then return end
|
||||
minetest.add_particlespawner({
|
||||
amount = 80,
|
||||
time = .1,
|
||||
|
|
|
@ -19,7 +19,7 @@ quake.register_grenade("quake:grenade", {
|
|||
textures = {"quake_bullet_rocket.png"},
|
||||
collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
|
||||
explosion_range = 4,
|
||||
duration = 2,
|
||||
duration = 1.5,
|
||||
gravity = true,
|
||||
on_destroy = quake.grenade_explode,
|
||||
particle = {
|
||||
|
|
|
@ -102,14 +102,17 @@ function grenade_set_entity(name, def)
|
|||
|
||||
function grenade_entity:_destroy()
|
||||
|
||||
spawn_particles_sphere(self.object:get_pos(), self.initial_properties.explosion_texture)
|
||||
|
||||
if self.initial_properties.on_destroy then
|
||||
self.initial_properties.on_destroy(self)
|
||||
self.initial_properties.on_destroy(self)
|
||||
end
|
||||
|
||||
-- spawna le particelle
|
||||
spawn_particles_sphere(self.object:get_pos(), self.initial_properties.explosion_texture)
|
||||
|
||||
self.object:remove()
|
||||
|
||||
|
||||
end
|
||||
|
||||
function grenade_entity:get_staticdata(self)
|
||||
|
@ -128,7 +131,7 @@ function grenade_set_entity(name, def)
|
|||
if staticdata ~= "" and staticdata ~= nil then
|
||||
self.p_name = staticdata -- nome utente come staticdata
|
||||
self.lifetime = 0
|
||||
self.sliding = 1
|
||||
self.sliding = 0
|
||||
self.particle = 0
|
||||
self.object:set_armor_groups({immortal = 1})
|
||||
else
|
||||
|
@ -146,19 +149,33 @@ function grenade_set_entity(name, def)
|
|||
local velocity = obj:get_velocity()
|
||||
|
||||
local pos = obj:getpos()
|
||||
if moveresult.collides and moveresult.collisions[1] and vector.distance(moveresult.collisions[1].old_velocity, velocity) > 4 then
|
||||
--print("collido")
|
||||
velocity[moveresult.collisions[1].axis] = moveresult.collisions[1].old_velocity[moveresult.collisions[1].axis] * -0.5 -- Invert velocity and reduce it a bit
|
||||
obj:set_velocity(velocity)
|
||||
--print(velocity.y)
|
||||
end
|
||||
|
||||
if moveresult.collides and moveresult.collisions[1] and not vector.equals(moveresult.collisions[1].old_velocity, velocity) and vector.distance(moveresult.collisions[1].old_velocity, velocity) > 4 then
|
||||
if math.abs(moveresult.collisions[1].old_velocity.x - velocity.x) > 5 then -- Check for a large reduction in velocity
|
||||
velocity.x = moveresult.collisions[1].old_velocity.x * -0.5 -- Invert velocity and reduce it a bit
|
||||
end
|
||||
|
||||
if math.abs(moveresult.collisions[1].old_velocity.y - velocity.y) > 5 then -- Check for a large reduction in velocity
|
||||
velocity.y = moveresult.collisions[1].old_velocity.y * -0.3 -- Invert velocity and reduce it a bit
|
||||
end
|
||||
|
||||
if self.sliding == 1 and velocity.y == 0 then -- Check if grenade is sliding
|
||||
self.sliding = 2 -- Multiplies drag by 2
|
||||
elseif self.sliding > 1 and velocity.y ~= 0 then
|
||||
self.sliding = 1 -- Doesn't affect drag
|
||||
if math.abs(moveresult.collisions[1].old_velocity.z - velocity.z) > 5 then -- Check for a large reduction in velocity
|
||||
velocity.z = moveresult.collisions[1].old_velocity.z * -0.5 -- Invert velocity and reduce it a bit
|
||||
end
|
||||
|
||||
obj:set_velocity(velocity)
|
||||
end
|
||||
|
||||
--[[
|
||||
print("#########################")
|
||||
print(dump(velocity))
|
||||
print("#########################")
|
||||
]]
|
||||
|
||||
if self.sliding == 0 and velocity.y == 0 then -- Check if grenade is sliding
|
||||
self.sliding = 1 -- Multiplies drag by 2
|
||||
elseif self.sliding > 0 and velocity.y ~= 0 then
|
||||
self.sliding = 0 -- Doesn't affect drag
|
||||
end
|
||||
|
||||
if self.sliding > 1 then -- Is the grenade sliding?
|
||||
|
@ -166,25 +183,44 @@ function grenade_set_entity(name, def)
|
|||
obj:set_velocity(vector.new(0, -9.8, 0)) -- Make sure it stays unmoving
|
||||
obj:set_acceleration(vector.new())
|
||||
end
|
||||
else
|
||||
local norm_velocity = vector.normalize(velocity)
|
||||
end
|
||||
--else
|
||||
local direction = vector.normalize(velocity)
|
||||
local node = minetest.get_node(pos)
|
||||
local speed = vector.length(velocity)
|
||||
local drag = math.max(minetest.registered_nodes[node.name].liquid_viscosity, 0.1)
|
||||
local yaw = minetest.dir_to_yaw(norm_velocity)
|
||||
local drag = math.max(minetest.registered_nodes[node.name].liquid_viscosity, 0.1) * self.sliding
|
||||
local yaw = minetest.dir_to_yaw(direction)
|
||||
local speed = vector.length(velocity)
|
||||
local pitch = math.acos(velocity.y/speed) - math.pi/3
|
||||
obj:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch})
|
||||
--print(drag)
|
||||
local acceleration = vector.multiply(velocity, -drag)
|
||||
--local acceleration = vector.multiply(direction, -drag)
|
||||
--print(acceleration.y)
|
||||
|
||||
|
||||
|
||||
acceleration.x = acceleration.x * (self.sliding * 5 * 2 + 1)
|
||||
acceleration.y = acceleration.y - 10 * ((7 - drag) / 7)
|
||||
acceleration.z = acceleration.z * (self.sliding * 5 * 2 + 1)
|
||||
|
||||
--[[
|
||||
print("XXXXXXXXXXXXXXXXXXXXXXXXXXXX")
|
||||
print(acceleration.x * (self.sliding * 5 * 2 + 1))
|
||||
print(-direction.x * 13 * (self.sliding + 1))
|
||||
print("XXXXXXXXXXXXXXXXXXXXXXXXXXXX")
|
||||
print("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ")
|
||||
print(acceleration.z * (self.sliding * 5 * 2 + 1))
|
||||
print(-direction.z * 13 * (self.sliding + 1))
|
||||
print("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ")
|
||||
]]
|
||||
|
||||
obj:set_acceleration(acceleration)
|
||||
--[[
|
||||
obj:set_acceleration({
|
||||
x = -norm_velocity.x * (self.initial_properties.throw_speed/2) * self.sliding,
|
||||
x = -direction.x * (self.initial_properties.throw_speed/2) * self.sliding,
|
||||
y = -9.8 * drag,
|
||||
z = -norm_velocity.z * (self.initial_properties.throw_speed/2) * self.sliding,
|
||||
z = -direction.z * (self.initial_properties.throw_speed/2) * self.sliding,
|
||||
})
|
||||
]]
|
||||
|
||||
|
@ -192,13 +228,13 @@ function grenade_set_entity(name, def)
|
|||
|
||||
|
||||
--[[
|
||||
local norm_velocity = vector.normalize(velocity)
|
||||
local direction = vector.normalize(velocity)
|
||||
obj:set_acceleration({
|
||||
x = -norm_velocity.x * self.initial_properties.acceleration * self.sliding,
|
||||
x = -direction.x * self.initial_properties.acceleration * self.sliding,
|
||||
y = -9.8,
|
||||
z = -norm_velocity.z * self.initial_properties.acceleration * self.sliding,
|
||||
z = -direction.z * self.initial_properties.acceleration * self.sliding,
|
||||
})]]
|
||||
end
|
||||
--end
|
||||
|
||||
if self.initial_properties.particle and self.particle >= 4 then
|
||||
self.particle = 0
|
||||
|
@ -258,7 +294,7 @@ end
|
|||
|
||||
--aggiunge le particelle dell'esplosione
|
||||
function spawn_particles_sphere(pos, particle_texture)
|
||||
|
||||
if not pos then return end
|
||||
minetest.add_particlespawner({
|
||||
amount = 80,
|
||||
time = .1,
|
||||
|
|
|
@ -2,8 +2,8 @@ quake.explode = function(self)
|
|||
local explosion_range = self.initial_properties.explosion_range
|
||||
local explosion_damage = self.initial_properties.explosion_damage
|
||||
local origin = self.object:get_pos()
|
||||
local objs = minetest:get_objects_inside_radius(origin, explosion_range)
|
||||
|
||||
local objs = minetest.env:get_objects_inside_radius(origin, explosion_range)
|
||||
local entities = {}
|
||||
-- se ho colpito qualcosa
|
||||
if objs then
|
||||
for _, obj in ipairs(objs) do
|
||||
|
@ -24,21 +24,27 @@ quake.explode = function(self)
|
|||
quake.shoot(self.p_name, obj, (damage/5), false)
|
||||
end
|
||||
end
|
||||
--[[
|
||||
elseif obj:get_luaentity() then
|
||||
local entity = obj:get_luaentity()
|
||||
if entity.initial_properties ~= nil then
|
||||
if entity.initial_properties.is_bullet or entity.initial_properties.is_grenade then
|
||||
--distrugge sia il proiettile con cui collide che se stesso
|
||||
entity:_destroy()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
]]
|
||||
|
||||
elseif obj ~= self.object and obj:get_luaentity() then
|
||||
local entity = obj:get_luaentity()
|
||||
table.insert(entities, entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #entities == 0 then return end
|
||||
self.object:remove()
|
||||
for _,entity in pairs(entities) do
|
||||
if entity.initial_properties ~= nil then
|
||||
if entity.initial_properties.is_bullet or entity.initial_properties.is_grenade then
|
||||
--distrugge sia il proiettile con cui collide che se stesso
|
||||
entity:_destroy()
|
||||
--return true --perchè ho attivato un'altra entità che esploda
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--return false --non ho attivato un'altra entità
|
||||
end
|
||||
|
||||
|
||||
|
@ -46,9 +52,13 @@ quake.grenade_explode = function(self)
|
|||
local explosion_range = self.initial_properties.explosion_range
|
||||
local explosion_damage = self.initial_properties.explosion_damage
|
||||
local origin = self.object:get_pos()
|
||||
if origin.x == nil or origin.y == nil or origin.z == nil then return end
|
||||
local objs = minetest:get_objects_inside_radius(origin, explosion_range)
|
||||
|
||||
if origin == nil then return end
|
||||
if origin.x == nil or origin.y == nil or origin.z == nil then return end
|
||||
|
||||
|
||||
local objs = minetest.env:get_objects_inside_radius(origin, explosion_range)
|
||||
local entities = {}
|
||||
-- se ho colpito qualcosa
|
||||
if objs then
|
||||
for _, obj in ipairs(objs) do
|
||||
|
@ -65,19 +75,25 @@ quake.grenade_explode = function(self)
|
|||
quake.shoot(self.p_name, obj, damage, false)
|
||||
|
||||
end
|
||||
--[[
|
||||
elseif obj:get_luaentity() then
|
||||
local entity = obj:get_luaentity()
|
||||
if entity.initial_properties ~= nil then
|
||||
if entity.initial_properties.is_bullet or entity.initial_properties.is_grenade then
|
||||
--distrugge sia il proiettile con cui collide che se stesso
|
||||
entity:_destroy()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
]]
|
||||
end
|
||||
|
||||
elseif obj ~= self.object and obj:get_luaentity() then
|
||||
local entity = obj:get_luaentity()
|
||||
table.insert(entities, entity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #entities == 0 then return end
|
||||
self.object:remove()
|
||||
for _,entity in pairs(entities) do
|
||||
if entity.initial_properties ~= nil then
|
||||
if entity.initial_properties.is_bullet or entity.initial_properties.is_grenade then
|
||||
--distrugge sia il proiettile con cui collide che se stesso
|
||||
entity:_destroy()
|
||||
--return true --perchè ho attivato un'altra entità che esploda
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--return false --non ho attivato un'altra entità
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue