flight and entities improvements

This commit is contained in:
Alexsandro Percy 2023-06-29 20:04:13 -03:00
parent 3cc68c379f
commit 85227b0d7b
6 changed files with 97 additions and 40 deletions

24
common_entities.lua Normal file
View File

@ -0,0 +1,24 @@
--
-- seat pivot
--
minetest.register_entity('airutils:seat_base',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "airutils_seat_base.b3d",
textures = {"airutils_alpha.png",},
},
on_activate = function(self,std)
self.sdata = minetest.deserialize(std) or {}
if self.sdata.remove then self.object:remove() end
end,
get_staticdata=function(self)
self.sdata.remove=true
return minetest.serialize(self.sdata)
end,
})

View File

@ -33,6 +33,7 @@ if not minetest.settings:get_bool('airutils.disable_repair') then
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_repair.lua")
end
airutils.get_wind = dofile(minetest.get_modpath("airutils") .. DIR_DELIM ..'/wind.lua')
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "common_entities.lua")
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_wind.lua")
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "inventory_management.lua")
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "light.lua")

View File

@ -106,6 +106,24 @@ function airutils.on_step(self,dtime,colinfo)
self.time_total=self.time_total+self.dtime
end
local function ground_pitch(self, longit_speed, curr_pitch)
newpitch = curr_pitch
-- adjust pitch at ground
if math.abs(longit_speed) < self._tail_lift_max_speed then
--minetest.chat_send_all(math.abs(longit_speed))
local speed_range = self._tail_lift_max_speed - self._tail_lift_min_speed
local percentage = 1-((math.abs(longit_speed) - self._tail_lift_min_speed)/speed_range)
if percentage > 1 then percentage = 1 end
if percentage < 0 then percentage = 0 end
local angle = self._tail_angle * percentage
local calculated_newpitch = math.rad(angle)
if newpitch < calculated_newpitch then newpitch = calculated_newpitch end --ja aproveita o pitch atual se ja estiver cerrto
if newpitch > math.rad(self._tail_angle) then newpitch = math.rad(self._tail_angle) end --não queremos arrastar o cauda no chão
end
return newpitch
end
function airutils.logic(self)
local velocity = self.object:get_velocity()
local curr_pos = self.object:get_pos()
@ -256,17 +274,7 @@ function airutils.logic(self)
-- adjust pitch at ground
if math.abs(longit_speed) > self._tail_lift_min_speed then
if math.abs(longit_speed) < self._tail_lift_max_speed then
--minetest.chat_send_all(math.abs(longit_speed))
local speed_range = self._tail_lift_max_speed - self._tail_lift_min_speed
percentage = 1-((math.abs(longit_speed) - self._tail_lift_min_speed)/speed_range)
if percentage > 1 then percentage = 1 end
if percentage < 0 then percentage = 0 end
local angle = self._tail_angle * percentage
local calculated_newpitch = math.rad(angle)
if newpitch < calculated_newpitch then newpitch = calculated_newpitch end --ja aproveita o pitch atual se ja estiver cerrto
if newpitch > math.rad(self._tail_angle) then newpitch = math.rad(self._tail_angle) end --não queremos arrastar o cauda no chão
end
newpitch = ground_pitch(self, longit_speed, newpitch)
else
if math.abs(longit_speed) < self._tail_lift_min_speed then
newpitch = math.rad(self._tail_angle)
@ -351,8 +359,26 @@ function airutils.logic(self)
end
local new_accel = accel
if longit_speed > 1.5 then
new_accel = airutils.getLiftAccel(self, velocity, new_accel, longit_speed, roll, curr_pos, self._lift, 15000)
if longit_speed > self._min_speed*0.66 then
--[[lets do something interesting:
here I'll fake the longit speed effect for takeoff, to force the airplane
to use more runway
]]--
local factorized_longit_speed = longit_speed
if is_flying == false and airutils.quadBezier then
local takeoff_speed = self._min_speed * 4 --so first I'll consider the takeoff speed 4x the minimal flight speed
if longit_speed < takeoff_speed and longit_speed > self._min_speed then -- then if the airplane is above the mininam speed and bellow the take off
local scale = (longit_speed*1)/takeoff_speed --get a scale of current longit speed relative to takeoff speed
if scale == nil then scale = 0 end --lets avoid any nil
factorized_longit_speed = airutils.quadBezier(scale, self._min_speed, longit_speed, longit_speed) --here the magic happens using a bezier curve
--minetest.chat_send_all("factor: " .. factorized_longit_speed .. " - longit: " .. longit_speed .. " - scale: " .. scale)
if factorized_longit_speed < 0 then factorized_longit_speed = 0 end --lets avoid negative numbers
if factorized_longit_speed == nil then factorized_longit_speed = longit_speed end --and nil numbers
end
end
local ceiling = 15000
new_accel = airutils.getLiftAccel(self, velocity, new_accel, factorized_longit_speed, roll, curr_pos, self._lift, ceiling, self._wing_span)
end
-- end lift

View File

@ -30,7 +30,7 @@ function airutils.pilot_formspec(name)
if ent._yaw_by_mouse then yaw = "true" end
basic_form = basic_form.."button[1,1.0;4,1;turn_on;Start/Stop Engines]"
basic_form = basic_form.."button[1,2.1;4,1;go_out;Go Offboard]"
basic_form = basic_form.."button[1,2.1;4,1;go_out;Go Out!]"
basic_form = basic_form.."button[1,3.2;4,1;hud;Show/Hide Gauges]"
basic_form = basic_form.."button[1,4.3;4,1;inventory;Show Inventory]"
basic_form = basic_form.."checkbox[1,5.7;yaw;Yaw by mouse;"..yaw.."]"

View File

@ -552,6 +552,10 @@ function airutils.paint_with_mask(self, colstr, target_texture, mask_texture)
end
function airutils.add_destruction_effects(pos, radius)
local node = airutils.nodeatpos(pos)
local is_liquid = false
if (node.drawtype == 'liquid' or node.drawtype == 'flowingliquid') then is_liquid = true end
minetest.sound_play("airutils_explode", {
pos = pos,
max_hear_distance = 100,
@ -559,32 +563,34 @@ function airutils.add_destruction_effects(pos, radius)
fade = 0.0,
pitch = 1.0,
}, true)
minetest.add_particle({
pos = pos,
velocity = vector.new(),
acceleration = vector.new(),
expirationtime = 0.4,
size = radius * 10,
collisiondetection = false,
vertical = false,
texture = "airutils_boom.png",
glow = 15,
})
minetest.add_particlespawner({
amount = 32,
time = 0.5,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x = -10, y = -10, z = -10},
maxvel = {x = 10, y = 10, z = 10},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 1,
maxexptime = 2.5,
minsize = radius * 3,
maxsize = radius * 5,
texture = "airutils_boom.png",
})
if is_liquid == false then
minetest.add_particle({
pos = pos,
velocity = vector.new(),
acceleration = vector.new(),
expirationtime = 0.4,
size = radius * 10,
collisiondetection = false,
vertical = false,
texture = "airutils_boom.png",
glow = 15,
})
minetest.add_particlespawner({
amount = 32,
time = 0.5,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x = -10, y = -10, z = -10},
maxvel = {x = 10, y = 10, z = 10},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 1,
maxexptime = 2.5,
minsize = radius * 3,
maxsize = radius * 5,
texture = "airutils_boom.png",
})
end
minetest.add_particlespawner({
amount = 64,
time = 1.0,

BIN
textures/airutils_alpha.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB