added autopilot button, autopilot adjusted

master
Alexsandro Percy 2022-05-03 11:54:23 -03:00
parent f9e779efab
commit 0842ebe2d9
5 changed files with 22 additions and 20 deletions

View File

@ -38,11 +38,6 @@ function pa28.physics(self)
self.object:set_velocity(vnew)
end
if pa28.mode == 1 then
local new_velocity = vector.add(vel, {x=0,y=mobkit.gravity * self.dtime,z=0})
self.object:set_velocity(new_velocity)
end
if pa28.mode == 2 then
self.object:set_acceleration({x=0,y=mobkit.gravity,z=0})
end

View File

@ -171,9 +171,7 @@ minetest.register_entity("pa28:pa28", {
_energy = 0.001,
_last_vel = {x=0,y=0,z=0},
_longit_speed = 0,
_land_retracted = true,
_show_hud = false,
_instruction_mode = false, --flag to intruction mode
_command_is_given = false, --flag to mark the "owner" of the commands now
_autopilot = false,
_auto_pilot_altitude = 0,

View File

@ -56,7 +56,7 @@ function pa28.pilot_formspec(name)
local copilot_name = "test"
basic_form = basic_form.."button[1,1.0;4,1;turn_on;Start/Stop Engines]"
basic_form = basic_form.."button[1,2.0;4,1;hud;Show/Hide Gauges]"
--basic_form = basic_form.."button[1,3.0;4,1;turn_auto_pilot_on;Auto Pilot]"
basic_form = basic_form.."button[1,3.0;4,1;turn_auto_pilot_on;Auto Pilot]"
basic_form = basic_form.."button[1,4.0;4,1;pass_control;Pass the Control]"
basic_form = basic_form.."checkbox[1,5.8;flap_is_down;Flaps down;"..flap_is_down.."]"
basic_form = basic_form.."checkbox[1,6.6;light;Landing Light;"..light.."]"
@ -125,7 +125,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end
if fields.turn_auto_pilot_on then
--
ent._autopilot = true
minetest.chat_send_player(ent.driver_name,core.colorize('#00ff00', " >>> Autopilot on"))
end
if fields.pass_control then
if ent._command_is_given == true then

View File

@ -37,9 +37,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
"* Forward: go down flying - nose down \n",
"* Left/right: Turn to left/right, work on and out ground. \n",
"* Left and Right together: center all commands \n",
"* Sneak and Jump together (normal): activates the autopilot \n",
"* Sneak and Jump together (instruction mode): give/take the \n",
" controls to/from pilot student \n",
"* Sneak and Jump together: activates the autopilot \n",
"* Aux1 (E) and Jump together: give/take the \n",
" controls to/from copilot \n",
"* Up and Down together: enable/disable HUD \n",
"* E and Right click: inventory (only external) \n"
}
@ -58,8 +58,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
"In front of the pilot is the instrument panel. \n",
"It's used to obtain important flight information. \n",
"The climber is the instrument that indicates the rate \n",
" of climb and descent, it's on the left of the \n",
" panel, marked with the letter C in blue. \n",
" of climb or descent, marked with the letter C in blue. \n",
"The speed indicator indicates the longitudinal speed of \n",
" the airplane. Is marked with the letter S in white. \n",
"The power gauge indicates the power applied to the \n",
@ -68,7 +67,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
" It's marked with the green F.\n",
"The altimeter, with values multiplied by 100, \n",
" indicates the current height. \n",
"At Panel center you see the compass, used for navigation."
"At Panel center you see the compass, used for navigation.\n",
" The compass have a second function as Automatic \n",
" direction finding (ADF). It can be activated through \n",
" the plane menu, checking it and setting the \n",
" destination coordinates."
}
local panel_form = table.concat({
"formspec_version[3]",

View File

@ -457,7 +457,7 @@ function pa28.flightstep(self)
---------------------
-- change the driver
---------------------
if passenger and self._last_time_command >= 1 and self._instruction_mode == true then
if passenger and self._last_time_command >= 1 then
if self._command_is_given == true then
if ctrl.sneak or ctrl.jump or ctrl.up or ctrl.down or ctrl.right or ctrl.left then
self._last_time_command = 0
@ -465,7 +465,7 @@ function pa28.flightstep(self)
airutils.transfer_control(self, false)
end
else
if ctrl.sneak == true and ctrl.jump == true then
if ctrl.aux1 == true and ctrl.jump == true then
self._last_time_command = 0
--trasnfer the control to student
airutils.transfer_control(self, true)
@ -475,7 +475,7 @@ function pa28.flightstep(self)
-----------
--autopilot
-----------
if self._instruction_mode == false and self._last_time_command >= 1 then
if self._last_time_command >= 1 then
if self._autopilot == true then
if ctrl.sneak or ctrl.jump or ctrl.up or ctrl.down or ctrl.right or ctrl.left then
self._last_time_command = 0
@ -554,6 +554,7 @@ function pa28.flightstep(self)
end
if longit_speed == 0 and is_flying == false and is_attached == false and self._engine_running == false then
if pa28.mode == 1 then self.object:set_velocity(vector.add(velocity, {x=0,y=mobkit.gravity * self.dtime,z=0})) end
return
end
@ -678,13 +679,17 @@ function pa28.flightstep(self)
if stop ~= true then --maybe == nil
self._last_accell = new_accel
self.object:move_to(curr_pos)
--self.object:set_velocity(velocity)
--solution to avoid rubber band bug
if player then
pa28.attach(self, player, self._instruction_mode)
pa28.attach(self, player, false)
end
if pa28.mode == 1 then
local gravity_velocity = {x=0,y=mobkit.gravity * self.dtime,z=0}
local new_velocity = vector.add(velocity, vector.multiply(new_accel, self.dtime))
new_velocity = vector.add(gravity_velocity, new_velocity)
--[[
new_velocity correction