Experimental player terminal velocity.
Note that for extremely long falls, something still needs to be done for items falling in parallel with players, since as it is right now, then fall at different speeds. Even with player velocity being limited, objects tend to fall at much slower speeds initially than players, and collide with unloaded areas and "settle" into node space, requriing an ABM to release them again. Instead, when a falling item collides with an unloaded area, we need a way to preserve its speed until the area is loaded, and then continue falling.
This commit is contained in:
parent
5a7567a73c
commit
fb256cf8bd
26
mods/nc_player_setup/freefall.lua
Normal file
26
mods/nc_player_setup/freefall.lua
Normal file
@ -0,0 +1,26 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local minetest, pairs
|
||||
= minetest, pairs
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
-- Terminal velocity = 50m/s, reasonable based on Wikipedia
|
||||
local friction = 0.0004
|
||||
|
||||
local cached = {}
|
||||
minetest.register_globalstep(function()
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local pname = player:get_player_name()
|
||||
local v = player:get_player_velocity()
|
||||
v = v.y < 0 and -v.y or 0
|
||||
local g = 1 - friction * v * v
|
||||
local og = cached[pname]
|
||||
if g ~= og then
|
||||
player:set_physics_override({gravity = g})
|
||||
cached[pname] = g
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
cached[player:get_player_name()] = nil
|
||||
end)
|
@ -7,3 +7,4 @@ nodecore.amcoremod()
|
||||
|
||||
include("setup")
|
||||
include("hotpotato")
|
||||
include("freefall")
|
||||
|
Loading…
x
Reference in New Issue
Block a user