Compare commits

...

3 Commits

4 changed files with 70 additions and 17 deletions

View File

@ -146,7 +146,7 @@ function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag
end
function airutils.set_pitch(self, dir, dtime)
local pitch_factor = 0.6
local pitch_factor = self._pitch_intensity or 0.6
local multiplier = pitch_factor*(dtime/airutils.ideal_step)
if dir == -1 then
--minetest.chat_send_all("cabrando")
@ -160,7 +160,7 @@ function airutils.set_pitch(self, dir, dtime)
end
function airutils.set_yaw(self, dir, dtime)
local yaw_factor = 25
local yaw_factor = self._yaw_intensity or 25
if dir == 1 then
self._rudder_angle = math.max(self._rudder_angle-(yaw_factor*dtime),-self._rudder_limit)
elseif dir == -1 then

View File

@ -14,6 +14,49 @@ function airutils.physics(self)
self.object:set_velocity(vel)
end
--buoyancy
local surface = nil
local surfnodename = nil
local spos = airutils.get_stand_pos(self)
spos.y = spos.y+0.01
-- get surface height
local snodepos = airutils.get_node_pos(spos)
local surfnode = airutils.nodeatpos(spos)
while surfnode and (surfnode.drawtype == 'liquid' or surfnode.drawtype == 'flowingliquid') do
surfnodename = surfnode.name
surface = snodepos.y +0.5
if surface > spos.y+self.height then break end
snodepos.y = snodepos.y+1
surfnode = airutils.nodeatpos(snodepos)
end
local new_velocity = nil
self.isinliquid = surfnodename
if surface then -- standing in liquid
self.isinliquid = true
end
local accell = {x=0, y=0, z=0}
self.water_drag = 0.1
if self.isinliquid then
local height = self.height
local submergence = min(surface-spos.y,height)/height
-- local balance = self.buoyancy*self.height
local buoyacc = airutils.gravity*(self.buoyancy-submergence)
--[[airutils.set_acceleration(self.object,
{x=-vel.x*self.water_drag,y=buoyacc-vel.y*abs(vel.y)*0.4,z=-vel.z*self.water_drag})]]--
accell = {x=-vel.x*self.water_drag,y=buoyacc-(vel.y*abs(vel.y)*0.4),z=-vel.z*self.water_drag}
--local v_accell = {x=0,y=buoyacc-(vel.y*abs(vel.y)*0.4),z=0}
--airutils.set_acceleration(self.object,v_accell)
new_velocity = vector.add(vel, vector.multiply(accell, self.dtime))
else
airutils.set_acceleration(self.object,{x=0,y=0,z=0})
self.isinliquid = false
new_velocity = vector.add(vel, {x=0,y=airutils.gravity * self.dtime,z=0})
--self.object:set_velocity(new_velocity)
end
-- bounciness
if self.springiness and self.springiness > 0 then
local vnew = vector.new(vel)
@ -39,5 +82,4 @@ function airutils.physics(self)
end
self.object:set_acceleration({x=0,y=airutils.gravity,z=0})
end

View File

@ -395,6 +395,7 @@ function airutils.logic(self)
--self.object:get_luaentity() --hack way to fix jitter on climb
--GAUGES
--minetest.chat_send_all('rate '.. climb_rate)
local climb_angle = airutils.get_gauge_angle(climb_rate)
--self.climb_gauge:set_attach(self.object,'',ALBATROS_D5_GAUGE_CLIMBER_POSITION,{x=0,y=0,z=climb_angle})
@ -404,6 +405,10 @@ function airutils.logic(self)
local speed_angle = airutils.get_gauge_angle(indicated_speed, -45)
--self.speed_gauge:set_attach(self.object,'',ALBATROS_D5_GAUGE_SPEED_POSITION,{x=0,y=0,z=speed_angle})
--adjust power indicator
local power_indicator_angle = airutils.get_gauge_angle(self._power_lever/10)
--self.power_gauge:set_attach(self.object,'',ALBATROS_D5_GAUGE_POWER_POSITION,{x=0,y=0,z=power_indicator_angle})
if is_attached then
if self._show_hud then
airutils.update_hud(player, climb_angle, speed_angle)
@ -412,10 +417,6 @@ function airutils.logic(self)
end
end
--adjust power indicator
local power_indicator_angle = airutils.get_gauge_angle(self._power_lever/10)
--self.power_gauge:set_attach(self.object,'',ALBATROS_D5_GAUGE_POWER_POSITION,{x=0,y=0,z=power_indicator_angle})
if is_flying == false then
-- new yaw
local turn_rate = math.rad(30)
@ -453,6 +454,10 @@ function airutils.logic(self)
end
function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
if self.hp_max <= 0 then
airutils.destroy(self)
end
if not puncher or not puncher:is_player() then
return
end
@ -473,7 +478,18 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
end
local is_attached = false
local player_attach = puncher:get_attach()
if player_attach then
if player_attach ~= self.object then
local slot_attach = player_attach:get_attach()
if slot_attach == self.object then is_attached = true end
else
is_attached = true
end
end
if puncher:get_attach() == self.object then is_attached = true end
--if puncher:get_attach() == self.pilot_seat_base then is_attached = true end
local itmstck=puncher:get_wielded_item()
local item_name = ""
@ -526,9 +542,9 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage)
if self.hp_max <= 0 then
airutils.destroy(self)
end
else
if self._custom_punch_when_attached then self._custom_punch_when_attached(self, puncher) end
end
end
function airutils.on_rightclick(self, clicker)

View File

@ -168,15 +168,10 @@ function airutils.destroy(self)
end
local pos = self.object:get_pos()
if self.fuel_gauge then self.fuel_gauge:remove() end
if self.power_gauge then self.power_gauge:remove() end
if self.climb_gauge then self.climb_gauge:remove() end
if self.speed_gauge then self.speed_gauge:remove() end
if self.engine then self.engine:remove() end
if self.pilot_seat_base then self.pilot_seat_base:remove() end
if self.passenger_seat_base then self.passenger_seat_base:remove() end
if self.stick then self.stick:remove() end
if self._destroy_parts_method then
self._destroy_parts_method(self)
end
airutils.destroy_inventory(self)
self.object:remove()