forked from mtcontrib/hangglider
Simplified gravity/movement internals
This commit is contained in:
parent
cc2cbd4973
commit
d087e9648d
113
init.lua
113
init.lua
@ -34,6 +34,9 @@
|
|||||||
-- Added blender-rendered overlay for struts using the actual model.
|
-- Added blender-rendered overlay for struts using the actual model.
|
||||||
-- Reduced airbreak penalty severity
|
-- Reduced airbreak penalty severity
|
||||||
-- gave glider limited durability.
|
-- gave glider limited durability.
|
||||||
|
-- Improved gravity adjustment function.
|
||||||
|
-- Changed airbreaking process
|
||||||
|
-- Removed airbreak penalty, as any 'advantage' seems minimal after new adjustments
|
||||||
|
|
||||||
|
|
||||||
local HUD_Overlay = true --show glider struts as overlay on HUD
|
local HUD_Overlay = true --show glider struts as overlay on HUD
|
||||||
@ -44,20 +47,33 @@ if HUD_Overlay then
|
|||||||
hangglider.id = {} -- hud id for displaying overlay with struts
|
hangglider.id = {} -- hud id for displaying overlay with struts
|
||||||
end
|
end
|
||||||
if debug then hangglider.debug = {} end -- hud id for debug data
|
if debug then hangglider.debug = {} end -- hud id for debug data
|
||||||
hangglider.airbreak = {} -- true if falling fast when equip
|
--hangglider.airbreak = {} -- true if falling fast when equip
|
||||||
|
|
||||||
minetest.register_entity("hangglider:airstopper", { --A one-instant entity that catches the player and slows them down.
|
minetest.register_entity("hangglider:airstopper", { --A one-instant entity that catches the player and stops them.
|
||||||
hp_max = 3,
|
|
||||||
is_visible = false,
|
is_visible = false,
|
||||||
|
physical = false,
|
||||||
immortal = true,
|
immortal = true,
|
||||||
attach = nil,
|
attach = nil,
|
||||||
on_step = function(self, _)
|
on_step = function(self, _)
|
||||||
if self.object:get_hp() ~= 1 then
|
local canExist = false
|
||||||
self.object:set_hp(self.object:get_hp() - 1)
|
if self.attach then
|
||||||
else
|
local player = self.attach
|
||||||
if self.attach then
|
if player:is_player() then
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
canExist = true
|
||||||
|
if player:get_player_velocity().y < 0.5 and player:get_player_velocity().y > -0.5 then
|
||||||
|
--Let go when the player actually stops, as that's the whole point.
|
||||||
|
if hangglider.use[pname] then
|
||||||
|
minetest.add_entity(player:get_pos(), "hangglider:glider"):set_attach(player, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
||||||
|
end
|
||||||
|
canExist = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not canExist then
|
||||||
self.attach:set_detach()
|
self.attach:set_detach()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
if not canExist then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -83,58 +99,9 @@ minetest.register_entity("hangglider:glider", {
|
|||||||
if not (mrn_name.walkable or (mrn_name.drowning and mrn_name.drowning == 1)) then
|
if not (mrn_name.walkable or (mrn_name.drowning and mrn_name.drowning == 1)) then
|
||||||
canExist = true
|
canExist = true
|
||||||
local vel = player:get_player_velocity()
|
local vel = player:get_player_velocity()
|
||||||
local grav = player:get_physics_override().gravity
|
|
||||||
if debug then player:hud_change(hangglider.debug[pname].id, "text", vel.y..', '..grav..', '..tostring(hangglider.airbreak[pname])) end
|
if debug then player:hud_change(hangglider.debug[pname].id, "text", vel.y..', '..grav..', '..tostring(hangglider.airbreak[pname])) end
|
||||||
-- If airbreaking used, increase the descent progression to not give
|
|
||||||
-- mid-flight unequip/equip cycles a distance advantage.
|
player:set_physics_override({gravity = (vel.y + 2.0)/20})
|
||||||
if hangglider.airbreak[pname] then
|
|
||||||
if vel.y <= -4.0 then
|
|
||||||
grav = -0.2 --Extreme measures are needed, as sometimes speed will get a bit out of control
|
|
||||||
elseif vel.y <= -2.0 then
|
|
||||||
grav = -0.02
|
|
||||||
elseif vel.y <= -1.75 then
|
|
||||||
grav = 0.00125 -- *1
|
|
||||||
elseif vel.y <= -1.5 then
|
|
||||||
grav = 0.0025 -- *2
|
|
||||||
elseif vel.y <= -1.25 then
|
|
||||||
grav = 0.005 -- *2
|
|
||||||
elseif vel.y <= -1 then
|
|
||||||
grav = 0.015 -- *3
|
|
||||||
elseif vel.y <= -0.75 then
|
|
||||||
grav = 0.04 -- *4
|
|
||||||
elseif vel.y <= -0.5 then
|
|
||||||
grav = 0.08 -- *4
|
|
||||||
elseif vel.y <= -0.25 then
|
|
||||||
grav = 0.12 -- *3
|
|
||||||
elseif vel.y <= 0 then
|
|
||||||
grav = 0.3 -- *3
|
|
||||||
else -- vel.y > 0
|
|
||||||
grav = 0.75 -- *1.5
|
|
||||||
end
|
|
||||||
else -- normal descent progression
|
|
||||||
if vel.y <= -4.0 then
|
|
||||||
grav = -0.2
|
|
||||||
elseif vel.y <= -2.0 then
|
|
||||||
grav = -0.02
|
|
||||||
elseif vel.y <= -1.5 then
|
|
||||||
grav = 0.00125
|
|
||||||
elseif vel.y <= -1.25 then
|
|
||||||
grav = 0.0025
|
|
||||||
elseif vel.y <= -1 then
|
|
||||||
grav = 0.005
|
|
||||||
elseif vel.y <= -0.75 then
|
|
||||||
grav = 0.01
|
|
||||||
elseif vel.y <= -0.5 then
|
|
||||||
grav = 0.02
|
|
||||||
elseif vel.y <= -0.25 then
|
|
||||||
grav = 0.04
|
|
||||||
elseif vel.y <= 0 then
|
|
||||||
grav = 0.1
|
|
||||||
else -- vel.y > 0
|
|
||||||
grav = 0.5
|
|
||||||
end
|
|
||||||
end
|
|
||||||
player:set_physics_override({gravity = grav})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -148,7 +115,7 @@ minetest.register_entity("hangglider:glider", {
|
|||||||
if HUD_Overlay then
|
if HUD_Overlay then
|
||||||
player:hud_change(hangglider.id[pname], "text", "blank.png")
|
player:hud_change(hangglider.id[pname], "text", "blank.png")
|
||||||
end
|
end
|
||||||
hangglider.airbreak[pname] = false
|
--hangglider.airbreak[pname] = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -192,7 +159,7 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
-- ht = {50,50,50},
|
-- ht = {50,50,50},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
hangglider.airbreak[pname] = false
|
--hangglider.airbreak[pname] = false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
@ -200,7 +167,7 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
hangglider.use[pname] = nil
|
hangglider.use[pname] = nil
|
||||||
if HUD_Overlay then hangglider.id[pname] = nil end
|
if HUD_Overlay then hangglider.id[pname] = nil end
|
||||||
if debug then hangglider.debug[pname] = nil end
|
if debug then hangglider.debug[pname] = nil end
|
||||||
hangglider.airbreak[pname] = nil
|
--hangglider.airbreak[pname] = nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_tool("hangglider:hangglider", {
|
minetest.register_tool("hangglider:hangglider", {
|
||||||
@ -216,27 +183,23 @@ minetest.register_tool("hangglider:hangglider", {
|
|||||||
if minetest.get_node(pos).name == "air" and not hangglider.use[pname] then --Equip
|
if minetest.get_node(pos).name == "air" and not hangglider.use[pname] then --Equip
|
||||||
minetest.sound_play("bedsheet", {pos=pos, max_hear_distance = 8, gain = 1.0})
|
minetest.sound_play("bedsheet", {pos=pos, max_hear_distance = 8, gain = 1.0})
|
||||||
if HUD_Overlay then user:hud_change(hangglider.id[pname], "text", "glider_struts.png") end
|
if HUD_Overlay then user:hud_change(hangglider.id[pname], "text", "glider_struts.png") end
|
||||||
|
local airbreak = false
|
||||||
local vel = user:get_player_velocity().y
|
local vel = user:get_player_velocity().y
|
||||||
if vel < -0.8 then -- engage mid-air, falling fast, so stop but ramp velocity more quickly
|
if vel < -1.5 then -- engage mid-air, falling fast, so stop but ramp velocity more quickly
|
||||||
hangglider.airbreak[pname] = true
|
--hangglider.airbreak[pname] = true
|
||||||
user:set_physics_override({
|
airbreak = true
|
||||||
gravity = 1,
|
|
||||||
jump = 0,
|
|
||||||
speed = 1.75,
|
|
||||||
})
|
|
||||||
local stopper = minetest.add_entity(pos, "hangglider:airstopper")
|
local stopper = minetest.add_entity(pos, "hangglider:airstopper")
|
||||||
stopper:get_luaentity().attach = user
|
stopper:get_luaentity().attach = user
|
||||||
user:set_attach( stopper, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
user:set_attach( stopper, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
||||||
else
|
end
|
||||||
user:set_physics_override({
|
user:set_physics_override({gravity = 0,jump=0,speed=1.75})
|
||||||
gravity = 0.02,
|
if not airbreak then
|
||||||
jump = 0,
|
|
||||||
speed = 1.75,
|
minetest.add_entity(user:get_pos(), "hangglider:glider"):set_attach(user, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
||||||
})
|
|
||||||
end
|
end
|
||||||
hangglider.use[pname] = true
|
hangglider.use[pname] = true
|
||||||
-- if minetest 0.4.x use this:
|
-- if minetest 0.4.x use this:
|
||||||
minetest.add_entity(user:get_pos(), "hangglider:glider"):set_attach(user, "", {x=0,y=0,z=0}, {x=0,y=0,z=0})
|
|
||||||
-- if minetest 5.x use this:
|
-- if minetest 5.x use this:
|
||||||
-- minetest.add_entity(user:get_pos(), "hangglider:glider"):set_attach(user, "", {x=0,y=10,z=0}, {x=0,y=0,z=0})
|
-- minetest.add_entity(user:get_pos(), "hangglider:glider"):set_attach(user, "", {x=0,y=10,z=0}, {x=0,y=0,z=0})
|
||||||
itemstack:set_wear(itemstack:get_wear() + 255)
|
itemstack:set_wear(itemstack:get_wear() + 255)
|
||||||
|
Loading…
Reference in New Issue
Block a user