From 50001c1993b0f1d2d6df63b22ee003cb5156b205 Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Wed, 24 Jan 2024 21:01:34 -0300 Subject: [PATCH] improved lib_copter --- lib_copter/control.lua | 11 +++++++++-- lib_copter/entities.lua | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib_copter/control.lua b/lib_copter/control.lua index 05f58f1..f58888e 100755 --- a/lib_copter/control.lua +++ b/lib_copter/control.lua @@ -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 diff --git a/lib_copter/entities.lua b/lib_copter/entities.lua index 3d8f223..513ee11 100644 --- a/lib_copter/entities.lua +++ b/lib_copter/entities.lua @@ -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) ------------------------------------------------------