improved lib_copter

This commit is contained in:
Alexsandro Percy 2024-01-24 21:01:34 -03:00
parent 446c58db33
commit 50001c1993
2 changed files with 42 additions and 6 deletions

View File

@ -5,11 +5,18 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELI
local function floating_auto_correction(self, dtime)
local factor = 1
local range = 0.03 --above and bellow
if self._wing_configuration > self._stable_collective + range or
self._wing_configuration < self._stable_collective - range then
return
end
--minetest.chat_send_player(self.driver_name, "antes: " .. self._air_float)
if self._wing_configuration > self._stable_collective then factor = -1 end
local time_correction = (dtime/airutils.ideal_step)
if time_correction < 1 then time_correction = 1 end
local intensity = 0.01
local intensity = 1
local correction = (intensity*factor) * time_correction
local new_wing_configuration = self._wing_configuration + correction
@ -101,7 +108,7 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit
--control lift
local collective_up_max = 1.2
local min_angle = self._min_collective
local collective_up = collective_up_max -- / 10
local collective_up = collective_up_max / 10
if ctrl.jump then
self._wing_configuration = self._wing_configuration + collective_up
--end

View File

@ -1,5 +1,27 @@
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "global_definitions.lua")
local function engine_set_sound_and_animation(self, is_flying)
is_flying = is_flying or false
--minetest.chat_send_all('test1 ' .. dump(self._engine_running) )
if self._engine_running or is_flying then
self.object:set_animation_frame_speed(100)
if self.sound_handle == nil then
self.sound_handle = minetest.sound_play({name = self._engine_sound},
{object = self.object, gain = 2.0,
pitch = 1.0,
max_hear_distance = 32,
loop = true,})
end
else
if self.sound_handle then
minetest.sound_stop(self.sound_handle)
self.sound_handle = nil
self.object:set_animation_frame_speed(0)
end
end
end
local function ground_pitch(self, longit_speed, curr_pitch)
local newpitch = curr_pitch
if self._last_longit_speed == nil then self._last_longit_speed = 0 end
@ -220,13 +242,20 @@ function airutils.logic_heli(self)
local ceiling = 5000
local blade_speed = self._rotor_speed or 15
local limit = 10
if self._engine_running == false then blade_speed = self._rotor_idle_speed or 12 end
local limit = (self._max_speed)
if self._engine_running == false then
if is_flying then
blade_speed = self._rotor_idle_speed or 12
if math.abs(longit_speed) > 0.5 then blade_speed = self._rotor_idle_speed + (self._rotor_speed - self._rotor_idle_speed) / 2 end
else
blade_speed = 1 --to avoid division by 0
end
end
local new_accel = airutils.getLiftAccel(self, {x=0, y=velocity.y, z=blade_speed}, {x=0, y=accel.y, z=blade_speed/self.dtime}, blade_speed, roll, curr_pos, self._lift, ceiling, self._wing_span)
local y_accell = new_accel.y
new_accel = vector.new(accel)
new_accel.y = y_accell
if new_accel.y > limit then new_accel.y = limit end --it isn't a rocket :/
if velocity.y > limit then new_accel.y = 0 end --it isn't a rocket :/
--wind effects
if airutils.wind and is_flying == true then
@ -271,7 +300,7 @@ function airutils.logic_heli(self)
------------------------------------------------------
-- sound and animation
------------------------------------------------------
airutils.engine_set_sound_and_animation(self)
engine_set_sound_and_animation(self, is_flying)
------------------------------------------------------