control fix and improvements

master
Alexsandro Percy 2022-05-11 18:15:59 -03:00
parent 52ffe480ec
commit 00b62c08f0
2 changed files with 28 additions and 30 deletions

View File

@ -133,7 +133,9 @@ function hidroplane.control(self, dtime, hull_direction, longit_speed, longit_dr
else
hidroplane.rudder_auto_correction(self, longit_speed, dtime)
end
hidroplane.elevator_auto_correction(self, longit_speed, dtime)
if airutils.elevator_auto_correction then
self._elevator_angle = airutils.elevator_auto_correction(self, longit_speed, self.dtime, hidroplane.max_speed, self._elevator_angle, hidroplane.elevator_limit, hidroplane.ideal_step, 100)
end
end
return retval_accel, stop
@ -171,20 +173,6 @@ function hidroplane.rudder_auto_correction(self, longit_speed, dtime)
end
end
function hidroplane.elevator_auto_correction(self, longit_speed, dtime)
local factor = 1
--if self._elevator_angle > -1.5 then factor = -1 end --here is the "compensator" adjusto to keep it stable
if self._elevator_angle > 0 then factor = -1 end
local correction = (hidroplane.elevator_limit*(longit_speed/10000)) * factor * (dtime/hidroplane.ideal_step)
local before_correction = self._elevator_angle
local new_elevator_angle = self._elevator_angle + correction
if math.sign(before_correction) ~= math.sign(new_elevator_angle) then
self._elevator_angle = 0
else
self._elevator_angle = new_elevator_angle
end
end
--obsolete, will be removed
function getAdjustFactor(curr_y, desired_y)
local max_difference = 0.1
@ -248,7 +236,9 @@ function hidroplane.autopilot(self, dtime, hull_direction, longit_speed, accel,
if longit_speed > 0 then
hidroplane.rudder_auto_correction(self, longit_speed, dtime)
hidroplane.elevator_auto_correction(self, longit_speed, dtime)
if airutils.elevator_auto_correction then
self._elevator_angle = airutils.elevator_auto_correction(self, longit_speed, self.dtime, hidroplane.max_speed, self._elevator_angle, hidroplane.elevator_limit, hidroplane.ideal_step, 100)
end
end
return retval_accel

View File

@ -478,24 +478,32 @@ function hidroplane.flightstep(self)
end
--ajustar angulo de ataque
local percentage = math.abs(((longit_speed * 100)/(hidroplane.min_speed + 5))/100)
if percentage > 1.5 then percentage = 1.5 end
self._angle_of_attack = self._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]]--
if longit_speed then
local percentage = math.abs(((longit_speed * 100)/(hidroplane.min_speed + 5))/100)
if percentage > 1.5 then percentage = 1.5 end
self._angle_of_attack = self._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, 5, 45, longit_speed, hidroplane.ideal_step, self.dtime)
end
end
--minetest.chat_send_all(self._angle_of_attack)
-- pitch
local speed_factor = 0
if longit_speed > hidroplane.min_speed then speed_factor = (velocity.y * math.rad(2)) end
local newpitch = math.rad(self._angle_of_attack) + speed_factor
local newpitch = math.rad(0)
if airutils.get_plane_pitch then
newpitch = airutils.get_plane_pitch(velocity, longit_speed, hidroplane.min_speed, self._angle_of_attack)
end
-- adjust pitch at ground
if is_flying == false then --isn't flying?