incrementaltp: respect physics overrides

master
cora 2021-09-21 12:58:57 +02:00
parent a63b0e40db
commit 8a59a40926
1 changed files with 31 additions and 13 deletions

View File

@ -7,10 +7,19 @@ incremental_tp.tpactive=false
-- for Clamity
incremental_tp.max_instantaneous_tp = {
x = 6,
y = 50,
z = 6
x = 5,
y = 45,
z = 5
}
function incremental_tp.get_actual_speed()
local po=minetest.localplayer:get_physics_override()
local rt=vector.new()
rt.x=incremental_tp.max_instantaneous_tp.x * po.speed
rt.y=incremental_tp.max_instantaneous_tp.y * po.speed
rt.z=incremental_tp.max_instantaneous_tp.z * po.speed
return rt
end
local wason=false
local function sign(n)
if n == 0 then
@ -21,7 +30,7 @@ local function sign(n)
end
local function max_dist_per(vec, time)
local mitp = vector.multiply(incremental_tp.max_instantaneous_tp,
local mitp = vector.multiply(incremental_tp.get_actual_speed(),
incremental_tp.fudge)
local nvec = {x = 0, y = 0, z = 0}
nvec.x = sign(vec.x) * math.min(math.abs(vec.x), mitp.x * time)
@ -41,10 +50,10 @@ local function tpstep(target, time, second, variance,sfunc)
end
wason=true
incremental_tp.tpactive=true
if math.abs(vec.x) + math.abs(vec.y) + math.abs(vec.z) < 1 then
if vector.distance(pos,target) < 3 then
minetest.localplayer:set_pos(target)
incremental_tp.tpactive=false
minetest.display_chat_message("Arrived at " .. minetest.pos_to_string(target))
--minetest.display_chat_message("Arrived at " .. minetest.pos_to_string(target))
if sfunc then
minetest.after(time, function()
sfunc(target)
@ -64,22 +73,31 @@ local function tpstep(target, time, second, variance,sfunc)
end
local nvec = max_dist_per(vec, intime)
minetest.localplayer:set_pos(vector.add(pos, nvec))
local trg=vector.add(pos, nvec)
--local safe=ws.find_closest_reachable_airpocket(trg)
minetest.localplayer:set_pos(trg)
minetest.after(intime, function()
tpstep(target, time, second - intime, variance,sfunc)
end)
end
function incremental_tp.tp(target, time, variance)
function incremental_tp.tpstep(target, time, variance,sfunc)
if incremental_tp.tpactive then return end
tpstep(target, time, 1, variance)
tpstep(target, time, 1, variance,sfunc)
end
function incremental_tp.tp(target, time, variance)
incremental_tp.tpactive=false
minetest.after(time,function()
tpstep(target,time,1,variance)
end)
end
function incremental_tp.tpafter(target,time,variance,sfunc)
if incremental_tp.tpactive then return end
tpstep(target,time,1,variance,sfunc)
incremental_tp.tpactive=false
minetest.after(time,function()
tpstep(target,time,1,variance,sfunc)
end)
end
if autofly then autofly.register_transport('itp',function(pos,name) incremental_tp.tp(pos,1) end) end