improved tild and speed control

This commit is contained in:
Alexsandro Percy 2024-01-30 20:30:37 -03:00
parent 5f78cbdd59
commit 9772e7270d
3 changed files with 59 additions and 30 deletions

View File

@ -76,9 +76,9 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit
self._last_time_command = 0.5
end
self._acceleration = 0
self._lat_acceleration = 0
local acc = 0
if not self._acceleration then self._acceleration = 0 end
if not self._lat_acceleration then self._lat_acceleration = 0 end
if self._engine_running then
--engine acceleration calc
@ -110,21 +110,39 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit
if is_flying or self.wheels then
local acc_fraction = (self._max_engine_acc / 40)*time_correction
if ctrl.up then
if longit_speed < self._max_speed then self._acceleration = self._acceleration + acc_fraction end
if longit_speed < self._max_speed then
self._acceleration = self._acceleration + acc_fraction
else
self._acceleration = 0
end
elseif ctrl.down then
if longit_speed > -1.0 then self._acceleration = self._acceleration + (-acc_fraction) end
if longit_speed > -1.0 then
self._acceleration = self._acceleration + (-acc_fraction)
else
self._acceleration = 0
end
else
acc = 0
self._acceleration = 0
end
self._acceleration = math.min(self._acceleration,self._max_engine_acc)
if is_flying then --why double check? because I dont want lateral movement when landed
if ctrl.right then
yaw_cmd = 1
if later_speed < self._max_speed and self._yaw_by_mouse then self._lat_acceleration = self._lat_acceleration + acc_fraction end
if later_speed < self._max_speed and self._yaw_by_mouse then
self._lat_acceleration = self._lat_acceleration + acc_fraction
else
self._lat_acceleration = 0
end
elseif ctrl.left then
yaw_cmd = -1
if later_speed > -self._max_speed and self._yaw_by_mouse then self._lat_acceleration = self._lat_acceleration + (-acc_fraction) end
if later_speed > -self._max_speed and self._yaw_by_mouse then
self._lat_acceleration = self._lat_acceleration + (-acc_fraction)
else
self._lat_acceleration = 0
end
else
self._lat_acceleration = 0
end
end
else
@ -153,8 +171,6 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit
--I'm desperate, center all!
if ctrl.right and ctrl.left then
self._wing_configuration = self._stable_collective
--self._elevator_angle = 0
--self._rudder_angle = 0
end
if ctrl.up and ctrl.down and self._last_time_command >= 0.5 then
@ -170,11 +186,6 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit
end
end
if is_flying then
--floating_auto_correction(self, self.dtime)
end
--minetest.chat_send_all(dump(self._wing_configuration))
return retval_accel, stop
end

View File

@ -19,23 +19,24 @@ local function engine_set_sound_and_animation(self, is_flying, newpitch, newroll
is_flying = is_flying or false
if self._engine_running then --engine running
if self._snd_last_roll ~= newroll or self._snd_last_pitch ~= newpitch then
if not self.sound_handle then
engineSoundPlay(self, 0.0, 0.9)
end
--self._cmd_snd
if self._snd_last_cmd ~= self._cmd_snd then
local increment = 0.0
self._snd_last_roll = newroll
self._snd_last_pitch = newpitch
if newroll ~= 0.0 or newpitch ~= 0.0 then increment = 0.1 else increment = 0.0 end
self._snd_last_cmd = self._cmd_snd
if self._cmd_snd then increment = 0.1 else increment = 0.0 end
engineSoundPlay(self, increment, 0.9)
end
self.object:set_animation_frame_speed(100)
else
if is_flying then --autorotation here
if self._snd_last_roll ~= newroll or self._snd_last_pitch ~= newpitch then
if self._snd_last_cmd ~= self._cmd_snd then
local increment = 0.0
self._snd_last_roll = newroll
self._snd_last_pitch = newpitch
if newroll ~= 0.0 or newpitch ~= 0.0 then increment = 0.1 else increment = 0.0 end
self._snd_last_cmd = self._cmd_snd
if self._cmd_snd then increment = 0.1 else increment = 0.0 end
engineSoundPlay(self, increment, 0.6)
end
@ -184,11 +185,28 @@ function airutils.logic_heli(self)
local newroll = 0
local newpitch = 0
if ctrl and is_flying then
local command_angle = math.rad(self._tilt_angle or 0)
if ctrl.up then newpitch = -command_angle end
if ctrl.down then newpitch = command_angle end
if ctrl.left then newroll = -command_angle end
if ctrl.right then newroll = command_angle end
local command_angle = self._tilt_angle or 0
local max_acc = self._max_engine_acc
local pitch_ammount = (math.abs(self._vehicle_acc or 0) * command_angle) / max_acc
if math.abs(longit_speed) >= self._max_speed then pitch_ammount = command_angle end --gambiarra pra continuar com angulo
pitch_ammount = math.rad(math.min(pitch_ammount, command_angle))
if ctrl.up then newpitch = -pitch_ammount end
if ctrl.down then newpitch = pitch_ammount end
local roll_ammount = (math.abs(self._lat_acc or 0) * command_angle) / max_acc
if math.abs(later_speed) >= self._max_speed then roll_ammount = command_angle end --gambiarra pra continuar com angulo
roll_ammount = math.rad(math.min(roll_ammount, command_angle))
if ctrl.left then newroll = -roll_ammount end
if ctrl.right then newroll = roll_ammount end
if ctrl.up or ctrl.down or ctrl.left or ctrl.right then
self._cmd_snd = true
else
self._cmd_snd = false
end
end
-- new yaw

View File

@ -440,7 +440,7 @@ function airutils.testImpact(self, velocity, position)
if self._last_speed_damage_time == nil then self._last_speed_damage_time = 0 end
self._last_speed_damage_time = self._last_speed_damage_time + self.dtime
if self._last_speed_damage_time > 2 then self._last_speed_damage_time = 2 end
if self._longit_speed > self._speed_not_exceed and self._last_speed_damage_time >= 2 then
if math.abs(self._longit_speed) > self._speed_not_exceed and self._last_speed_damage_time >= 2 then
self._last_speed_damage_time = 0
minetest.sound_play("airutils_collision", {
--to_player = self.driver_name,