improved flight controls

This commit is contained in:
Alexsandro Percy 2022-12-13 18:13:53 -03:00
parent eed3796736
commit 6733193290
4 changed files with 48 additions and 15 deletions

View File

@ -25,7 +25,7 @@ function delorean.control(self, dtime, hull_direction, longit_speed, longit_drag
end
--reversing
if not self.is_flying or self.is_flying == 0 then
if not self._is_flying or self._is_flying == 0 then
if ctrl.sneak and longit_speed <= 1.0 and longit_speed > -1.0 then
acc = -2
end
@ -47,7 +47,7 @@ function delorean.control(self, dtime, hull_direction, longit_speed, longit_drag
end
end
if not self.is_flying or self.is_flying == 0 then
if not self._is_flying or self._is_flying == 0 then
if longit_speed < 0 then
acc = 5
if (longit_speed + acc) > 0 then

View File

@ -394,6 +394,7 @@ minetest.register_entity("automobiles_delorean:delorean", {
_intensity = 4,
_delorean_type = 0,
_car_gravity = -automobiles_lib.gravity,
_is_flying = 0,
get_staticdata = function(self) -- unloaded/unloads ... is now saved
return minetest.serialize({
@ -565,6 +566,7 @@ minetest.register_entity("automobiles_delorean:delorean", {
local accel = vector.add(longit_drag,later_drag)
local stop = nil
local curr_pos = self.object:get_pos()
local player = nil
local is_attached = false
@ -582,21 +584,29 @@ minetest.register_entity("automobiles_delorean:delorean", {
end
--to fix the load on first time
self.is_flying = 0
if self._delorean_type == 1 then
local ent_propertioes = self.normal_kit:get_properties()
if ent_propertioes.mesh ~= "automobiles_delorean_time_machine_accessories.b3d" then
delorean.set_kit(self)
end
--start flight functions
if self.is_flying == 1 then
if self._is_flying == 1 then
if is_attached then
delorean.control_flight(self, player)
end
delorean.gravity_auto_correction(self, dtime)
--check if is near the ground, so revert the flight mode
local noded = automobiles_lib.nodeatpos(automobiles_lib.pos_shift(curr_pos,{y=-1}))
if (noded and noded.drawtype ~= 'airlike') then
if noded.drawtype ~= 'liquid' then
self._is_flying = 0
end
end
else
self._car_gravity = -automobiles_lib.gravity
end
delorean.gravity_auto_correction(self, dtime)
end
local is_breaking = false
@ -642,7 +652,6 @@ minetest.register_entity("automobiles_delorean:delorean", {
end
-- impacts and control
local curr_pos = self.object:get_pos()
self.object:move_to(curr_pos)
if is_attached then --and self.driver_name == self.owner then
local impact = automobiles_lib.get_hipotenuse_value(velocity, self.lastvelocity)
@ -787,7 +796,7 @@ minetest.register_entity("automobiles_delorean:delorean", {
-- end energy consumption --
--gravity works
if not self.is_flying or self.is_flying == 0 then
if not self._is_flying or self._is_flying == 0 then
accel.y = -automobiles_lib.gravity
else
local time_correction = (self.dtime/delorean.ideal_step)
@ -813,7 +822,7 @@ minetest.register_entity("automobiles_delorean:delorean", {
local newpitch = self._pitch --velocity.y * math.rad(6)
local newroll = 0
if self.is_flying == 1 then
if self._is_flying == 1 then
local turn_effect_speed = longit_speed
if turn_effect_speed > 10 then turn_effect_speed = 10 end
newroll = (-self._steering_angle/100)*(turn_effect_speed/10)

View File

@ -21,7 +21,7 @@ function delorean.gravity_auto_correction(self, dtime)
--minetest.chat_send_player(self.driver_name, "antes: " .. self._car_gravity)
if self._car_gravity > 0 then factor = -1 end
local time_correction = (dtime/delorean.ideal_step)
local intensity = 0.5
local intensity = 1
local correction = (intensity*factor) * time_correction
--minetest.chat_send_player(self.driver_name, correction)
local before_correction = self._car_gravity
@ -35,16 +35,18 @@ function delorean.gravity_auto_correction(self, dtime)
end
function delorean.control_flight(self, player)
local ctrl = player:get_player_control()
if ctrl.jump then
self._car_gravity = 4
elseif ctrl.sneak then
self._car_gravity = -4
if self._is_flying == 1 then
local ctrl = player:get_player_control()
if ctrl.jump then
self._car_gravity = 5
elseif ctrl.sneak then
self._car_gravity = -5
end
end
end
function delorean.set_wheels_mode(self, angle_factor)
if not self.is_flying or self.is_flying == 0 then
if not self._is_flying or self._is_flying == 0 then
--whell turn
self.lf_wheel:set_attach(self.front_suspension,'',{x=-delorean.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=delorean.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
@ -58,3 +60,13 @@ function delorean.set_wheels_mode(self, angle_factor)
self.rr_wheel:set_attach(self.rear_suspension,'',{x=delorean.rear_wheel_xpos+extra_space,y=0,z=0},{x=0,y=180,z=-90})
end
end
function delorean.turn_flight_mode(self)
if self._is_flying == 1 then
--initial lift
local curr_pos = self.object:get_pos()
curr_pos.y = curr_pos.y + 1.5
self.object:move_to(curr_pos)
end
end

View File

@ -23,6 +23,9 @@ function delorean.driver_formspec(name)
local yaw = "false"
if ent._yaw_by_mouse then yaw = "true" end
local flight = "false"
if ent._is_flying == 1 then flight = "true" end
local basic_form = table.concat({
"formspec_version[3]",
"size[6,7]",
@ -30,6 +33,7 @@ function delorean.driver_formspec(name)
basic_form = basic_form.."button[1,1.0;4,1;go_out;Go Offboard]"
basic_form = basic_form.."button[1,2.5;4,1;lights;Lights]"
if ent._delorean_type == 1 then basic_form = basic_form.."checkbox[1,4.0;flight;Flight Mode;"..flight.."]" end
basic_form = basic_form.."checkbox[1,5.5;yaw;Direction by mouse;"..yaw.."]"
minetest.show_formspec(name, "delorean:driver_main", basic_form)
@ -65,6 +69,14 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
ent._yaw_by_mouse = true
end
end
if fields.flight then
if ent._is_flying == 1 then
ent._is_flying = 0
else
ent._is_flying = 1
end
delorean.turn_flight_mode(ent)
end
end
end
minetest.close_formspec(name, "delorean:driver_main")