diff --git a/init.lua b/init.lua index 415224d..fc1cda5 100644 --- a/init.lua +++ b/init.lua @@ -306,7 +306,7 @@ end function airutils.get_plane_pitch(velocity, longit_speed, min_speed, angle_of_attack) local v_speed_factor = 0 - if longit_speed > min_speed then v_speed_factor = (velocity.y * math.rad(1)) end --the pitch for climbing os descenting + if longit_speed > min_speed then v_speed_factor = (velocity.y * math.rad(2)) end --the pitch for climbing or descenting local min_rotation_speed = min_speed/2 local scale_pitch_graph = ((longit_speed-min_rotation_speed)*1)/min_rotation_speed --lets use the min rotation speed for reference to when we will start the control work if scale_pitch_graph > 1 then scale_pitch_graph = 1 end --normalize to 100% @@ -325,6 +325,7 @@ function airutils.adjust_attack_angle_by_speed(angle_of_attack, min_angle, max_a local correction = (limit*(longit_speed/5000)) * factor * (dtime/ideal_step) --minetest.chat_send_all("angle: "..angle_of_attack.." - correction: "..correction) local new_angle_of_attack = angle_of_attack + correction + return new_angle_of_attack end diff --git a/lib_planes/control.lua b/lib_planes/control.lua index 0e3f99a..1b19273 100755 --- a/lib_planes/control.lua +++ b/lib_planes/control.lua @@ -146,8 +146,8 @@ function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag end function airutils.set_pitch(self, dir, dtime) - local pitch_factor = 12 - local multiplier = pitch_factor*dtime + local pitch_factor = 0.6 + local multiplier = pitch_factor*(dtime/airutils.ideal_step) if dir == -1 then --minetest.chat_send_all("cabrando") if self._elevator_angle > 0 then pitch_factor = pitch_factor * 2 end @@ -244,7 +244,7 @@ function airutils.autopilot(self, dtime, hull_direction, longit_speed, accel, cu if longit_speed > 0 then airutils.rudder_auto_correction(self, longit_speed, dtime) if airutils.elevator_auto_correction then - self._elevator_angle = airutils.elevator_auto_correction(self, longit_speed, self.dtime, airutils.max_speed, self._elevator_angle, airutils.elevator_limit, airutils.ideal_step, 100) + self._elevator_angle = airutils.elevator_auto_correction(self, longit_speed, self.dtime, airutils.max_speed, self._elevator_angle, airutils.elevator_limit, airutils.ideal_step, self._elevator_auto_estabilize) end end diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index 6f43056..97fe86f 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -48,10 +48,6 @@ function airutils.on_activate(self, staticdata, dtime_s) end airutils.param_paint(self, self._color) - --TODO - --[[if self._alternate_painting_texture and self._mask_painting_texture then - airutils.paint_with_mask(self, self._color, self._alternate_painting_texture, self._mask_painting_texture) - end]]-- self.object:set_armor_groups({immortal=1}) @@ -204,43 +200,56 @@ function airutils.logic(self) return end - --ajustar angulo de ataque - if longit_speed then - local percentage = math.abs(((longit_speed * 100)/(self._min_speed + 5))/100) - if percentage > 1.5 then percentage = 1.5 end - self._angle_of_attack = self._wing_angle_of_attack - ((self._elevator_angle / 20)*percentage) - if self._angle_of_attack < -0.5 then - self._angle_of_attack = -0.1 - self._elevator_angle = self._elevator_angle - 0.1 - end --limiting the negative angle]]-- - if self._angle_of_attack > 20 then - self._angle_of_attack = 20 - self._elevator_angle = self._elevator_angle + 0.1 - end --limiting the very high climb angle due to strange behavior]]-- - - --set the plane on level - if airutils.adjust_attack_angle_by_speed then - self._angle_of_attack = airutils.adjust_attack_angle_by_speed(self._angle_of_attack, 1, 6, 40, longit_speed, airutils.ideal_step, self.dtime) - end + --adjust climb indicator + local climb_rate = velocity.y + if climb_rate > 5 then climb_rate = 5 end + if climb_rate < -5 then + climb_rate = -5 end - --minetest.chat_send_all(self._angle_of_attack) - -- pitch local newpitch = math.rad(0) if airutils.get_plane_pitch then newpitch = airutils.get_plane_pitch(velocity, longit_speed, self._min_speed, self._angle_of_attack) end + --is an stall, force a recover + if longit_speed < self._min_speed and climb_rate < -4 and is_flying then + self._elevator_angle = 0 + self._angle_of_attack = -2 + newpitch = math.rad(self._angle_of_attack) + else + --ajustar angulo de ataque + if longit_speed > (self._min_speed) then + local percentage = math.abs(((longit_speed * 100)/(self._min_speed + 5))/100) + if percentage > 1.5 then percentage = 1.5 end + self._angle_of_attack = self._wing_angle_of_attack - ((self._elevator_angle / 10)*percentage) + + --set the plane on level + if airutils.adjust_attack_angle_by_speed then + --airutils.adjust_attack_angle_by_speed(angle_of_attack, min_angle, max_angle, limit, longit_speed, ideal_step, dtime) + self._angle_of_attack = airutils.adjust_attack_angle_by_speed(self._angle_of_attack, self._min_attack_angle, self._max_attack_angle, 40, longit_speed, airutils.ideal_step, self.dtime) + end + + if self._angle_of_attack < self._min_attack_angle then + self._angle_of_attack = self._min_attack_angle + self._elevator_angle = self._elevator_angle - 0.2 + end --limiting the negative angle]]-- + --[[if self._angle_of_attack > self._max_attack_angle then + self._angle_of_attack = self._max_attack_angle + self._elevator_angle = self._elevator_angle + 0.2 + end --limiting the very high climb angle due to strange behavior]]--]]-- + end + end + + --minetest.chat_send_all(self._angle_of_attack) -- adjust pitch at ground - local tail_lift_min_speed = 4 - local tail_lift_max_speed = 8 - if math.abs(longit_speed) > tail_lift_min_speed then - if math.abs(longit_speed) < tail_lift_max_speed then + 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 = tail_lift_max_speed - tail_lift_min_speed - percentage = 1-((math.abs(longit_speed) - tail_lift_min_speed)/speed_range) + 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 @@ -249,7 +258,7 @@ function airutils.logic(self) 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 else - if math.abs(longit_speed) < tail_lift_min_speed then + if math.abs(longit_speed) < self._tail_lift_min_speed then newpitch = math.rad(self._tail_angle) end end @@ -386,20 +395,6 @@ function airutils.logic(self) --self.object:get_luaentity() --hack way to fix jitter on climb - --adjust climb indicator - local climb_rate = velocity.y - if climb_rate > 5 then climb_rate = 5 end - if climb_rate < -5 then - climb_rate = -5 - end - - --is an stall, force a recover - if longit_speed < (self._min_speed / 2) and climb_rate < -3.5 and is_flying then - self._elevator_angle = 0 - self._angle_of_attack = -4 - newpitch = math.rad(self._angle_of_attack) - end - --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})