changed the flight mode to by velocity. But it can be changed by a variable set on init
parent
aed6957f61
commit
8d6098069d
|
@ -38,6 +38,13 @@ function pa28.physics(self)
|
|||
self.object:set_velocity(vnew)
|
||||
end
|
||||
|
||||
self.object:set_acceleration({x=0,y=mobkit.gravity,z=0})
|
||||
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
|
||||
|
||||
end
|
||||
|
|
16
forms.lua
16
forms.lua
|
@ -165,14 +165,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||
end
|
||||
end
|
||||
if fields.save_adf then
|
||||
if fields.adf_x then
|
||||
if tonumber(fields.adf_x, 10) ~= nil then
|
||||
ent._adf_destiny.x = tonumber(fields.adf_x, 10)
|
||||
if ent._adf_destiny then
|
||||
if fields.adf_x then
|
||||
if tonumber(fields.adf_x, 10) ~= nil then
|
||||
ent._adf_destiny.x = tonumber(fields.adf_x, 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
if fields.adf_z then
|
||||
if tonumber(fields.adf_z, 10) ~= nil then
|
||||
ent._adf_destiny.z = tonumber(fields.adf_z, 10)
|
||||
if fields.adf_z then
|
||||
if tonumber(fields.adf_z, 10) ~= nil then
|
||||
ent._adf_destiny.z = tonumber(fields.adf_z, 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
1
init.lua
1
init.lua
|
@ -9,6 +9,7 @@ pa28.max_engine_acc = 8.5
|
|||
pa28.lift = 10
|
||||
pa28.trunk_slots = 16
|
||||
pa28.plane_text = "PA28"
|
||||
pa28.mode = 1 --1 -> velocity 2 -> acceleration
|
||||
|
||||
dofile(minetest.get_modpath("pa28") .. DIR_DELIM .. "global_definitions.lua")
|
||||
dofile(minetest.get_modpath("pa28") .. DIR_DELIM .. "control.lua")
|
||||
|
|
|
@ -682,7 +682,27 @@ function pa28.flightstep(self)
|
|||
if player then
|
||||
pa28.attach(self, player, self._instruction_mode)
|
||||
end
|
||||
mobkit.set_acceleration(self.object, new_accel)
|
||||
|
||||
if pa28.mode == 1 then
|
||||
local new_velocity = vector.add(velocity, vector.multiply(new_accel, self.dtime))
|
||||
|
||||
--[[
|
||||
new_velocity correction
|
||||
under some circunstances the velocity exceeds the max value accepted by set_velocity and
|
||||
the game crashes with an overflow, so limiting the max velocity in each axis prevents the crash
|
||||
]]--
|
||||
local max_factor = 55
|
||||
local vel_adjusted = 40
|
||||
if new_velocity.x > max_factor then new_velocity.x = vel_adjusted end
|
||||
if new_velocity.x < -max_factor then new_velocity.x = -vel_adjusted end
|
||||
if new_velocity.z > max_factor then new_velocity.z = vel_adjusted end
|
||||
if new_velocity.z < -max_factor then new_velocity.z = -vel_adjusted end
|
||||
if new_velocity.y > max_factor then new_velocity.y = vel_adjusted end
|
||||
if new_velocity.y < -max_factor then new_velocity.y = -vel_adjusted end
|
||||
minetest.chat_send_all(dump(new_velocity))
|
||||
self.object:set_velocity(new_velocity)
|
||||
end
|
||||
if pa28.mode == 2 then mobkit.set_acceleration(self.object, new_accel) end
|
||||
else
|
||||
if stop == true then
|
||||
self.object:set_acceleration({x=0,y=0,z=0})
|
||||
|
@ -716,6 +736,7 @@ function pa28.flightstep(self)
|
|||
|
||||
--adjust climb indicator
|
||||
local climb_rate = velocity.y
|
||||
if self.isonground then climb_rate = 0 end
|
||||
if climb_rate > 5 then climb_rate = 5 end
|
||||
if climb_rate < -5 then
|
||||
climb_rate = -5
|
||||
|
|
Loading…
Reference in New Issue