improved delorean and fix of rag opening

This commit is contained in:
Alexsandro Percy 2023-12-27 14:26:49 -03:00
parent 0a45d9ab8a
commit 05b3460651
4 changed files with 68 additions and 22 deletions

View File

@ -430,8 +430,19 @@ minetest.register_entity("automobiles_delorean:delorean", {
_reverse_lights = 'automobiles_delorean:reverse_lights',
_turn_left_lights = 'automobiles_delorean:turn_left_light',
_turn_right_lights = 'automobiles_delorean:turn_right_light',
_textures_turn_lights_off = {"automobiles_turn.png", },
_textures_turn_lights_on = { "automobiles_turn_on.png", },
_extra_items_function = delorean.set_kit, --uses _car_type do change "skin"
_setmode = delorean.set_mode,
_control_function = delorean.control,
_LONGIT_DRAG_FACTOR = 0.12*0.12,
_LATER_DRAG_FACTOR = 8.0,
_max_acc_factor = 8.0,
_max_speed = 30,
_min_later_speed = 4.5,
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
@ -440,14 +451,15 @@ minetest.register_entity("automobiles_delorean:delorean", {
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
on_step = automobiles_lib.on_step,
--[[on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
--[[sound play control]]--
--sound play control--
self._last_time_collision_snd = self._last_time_collision_snd + dtime
if self._last_time_collision_snd > 1 then self._last_time_collision_snd = 1 end
self._last_time_drift_snd = self._last_time_drift_snd + dtime
if self._last_time_drift_snd > 1 then self._last_time_drift_snd = 1 end
--[[end sound control]]--
--end sound control--
local rotation = self.object:get_rotation()
local yaw = rotation.y
@ -548,9 +560,6 @@ minetest.register_entity("automobiles_delorean:delorean", {
pitch = 1.0,
})
end
--[[if self.damage > 100 then --if acumulated damage is greater than 100, adieu
automobiles_lib.destroy(self)
end]]--
end
--control
@ -636,11 +645,9 @@ minetest.register_entity("automobiles_delorean:delorean", {
self._turn_light_timer = 1
end
--[[
accell correction
under some circunstances the acceleration exceeds the max value accepted by set_acceleration and
the game crashes with an overflow, so limiting the max acceleration in each axis prevents the crash
]]--
--accell correction
--under some circunstances the acceleration exceeds the max value accepted by set_acceleration and
--the game crashes with an overflow, so limiting the max acceleration in each axis prevents the crash
local max_factor = 25
local acc_adjusted = 10
if accel.x > max_factor then accel.x = acc_adjusted end
@ -724,7 +731,7 @@ minetest.register_entity("automobiles_delorean:delorean", {
self.lastvelocity = self.object:get_velocity()
self._longit_speed = longit_speed
end,
end,]]--
on_punch = automobiles_lib.on_punch,
on_rightclick = automobiles_lib.on_rightclick,

View File

@ -48,10 +48,10 @@ end
function delorean.set_wheels_mode(self, angle_factor)
if not self._is_flying or self._is_flying == 0 then
--whell turn
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
--[[self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._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=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})]]--
else
local extra_space = 0.5
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos-extra_space,y=0,z=0},{x=0,y=0,z=90})
@ -133,6 +133,7 @@ function delorean.set_mode(self, is_attached, curr_pos, velocity, player, dtime)
end
end
end
delorean.set_wheels_mode(self, 0)
end
end

View File

@ -2,12 +2,7 @@
-- constants
--
delorean={}
delorean.LONGIT_DRAG_FACTOR = 0.12*0.12
delorean.LATER_DRAG_FACTOR = 8.0
delorean.gravity = automobiles_lib.gravity
delorean.max_speed = 30
delorean.max_acc_factor = 8
delorean.ideal_step = 0.2
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.lua")

View File

@ -389,6 +389,20 @@ function automobiles_lib.on_step(self, dtime)
local stop = nil
local curr_pos = self.object:get_pos()
if self._show_rag == true then
if self._windshield_pos and self._windshield_ext_rotation then
self.object:set_bone_position("windshield", self._windshield_pos, self._windshield_ext_rotation) --extended
end
if self.rag_rect then self.rag_rect:set_properties({is_visible=true}) end
if self.rag then self.rag:set_properties({is_visible=false}) end
else
if self._windshield_pos then
self.object:set_bone_position("windshield", self._windshield_pos, {x=0, y=0, z=0}) --retracted
end
if self.rag_rect then self.rag_rect:set_properties({is_visible=false}) end
if self.rag then self.rag:set_properties({is_visible=true}) end
end
local player = nil
local is_attached = false
if self.driver_name then
@ -404,6 +418,11 @@ function automobiles_lib.on_step(self, dtime)
end
end
--for flying
if self._setmode then
self._setmode(self, is_attached, curr_pos, velocity, player, dtime)
end
local is_breaking = false
if is_attached then
local ctrl = player:get_player_control()
@ -500,7 +519,11 @@ function automobiles_lib.on_step(self, dtime)
--minetest.chat_send_all(transmission_state)
--control
accel, stop = automobiles_lib.control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, target_acc_factor, self._max_speed, steering_angle_max, steering_speed)
local control = automobiles_lib.control
if self._control_function then
control = self._control_function
end
accel, stop = control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, target_acc_factor, self._max_speed, steering_angle_max, steering_speed)
else
self._show_lights = false
if self.sound_handle ~= nil then
@ -512,7 +535,7 @@ function automobiles_lib.on_step(self, dtime)
local angle_factor = self._steering_angle / 10
--whell turn
if self.lf_wheel and self.rf_wheel and self.lr_wheel and self.rr_wheel then
if self.lf_wheel and self.rf_wheel and self.lr_wheel and self.rr_wheel and self._is_flying ~= 1 then
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._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=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
@ -543,13 +566,19 @@ function automobiles_lib.on_step(self, dtime)
if self.lr_wheel then self.lr_wheel:set_animation_frame_speed( wheel_compensation * (12 - angle_factor)) end
if self.rr_wheel then self.rr_wheel:set_animation_frame_speed(-wheel_compensation * (12 + angle_factor)) end
end
else
--is flying
if self.lf_wheel then self.lf_wheel:set_animation_frame_speed(0) end
if self.rf_wheel then self.rf_wheel:set_animation_frame_speed(0) end
if self.lr_wheel then self.lr_wheel:set_animation_frame_speed(0) end
if self.rr_wheel then self.rr_wheel:set_animation_frame_speed(0) end
end
--drive wheel turn
if self._steering_ent then
self.steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=self._steering_angle*2})
else
self.object:set_bone_position("drive_wheel", {x=-0, y=0, z=0}, {x=0, y=0, z=-self._steering_angle*2})
self.object:set_bone_position("drive_wheel", {x=-0, y=0, z=0}, {x=0, y=0, z=-self._steering_angle*2})
end
@ -656,6 +685,20 @@ function automobiles_lib.on_step(self, dtime)
local newpitch = self._pitch --velocity.y * math.rad(6)
local newroll = 0
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)
if math.abs(self._steering_angle) < 1 then newroll = 0 end
--pitch
local max_pitch = 6
local h_vel_compensation = (((longit_speed * 2) * 100)/max_pitch)/100
if h_vel_compensation < 0 then h_vel_compensation = 0 end
if h_vel_compensation > max_pitch then h_vel_compensation = max_pitch end
newpitch = newpitch + (velocity.y * math.rad(max_pitch - h_vel_compensation))
end
self.object:set_rotation({x=newpitch,y=newyaw,z=newroll})
--saves last velocity for collision detection (abrupt stop)