incrementaltp: respect physics overrides
This commit is contained in:
parent
a63b0e40db
commit
8a59a40926
@ -7,10 +7,19 @@ incremental_tp.tpactive=false
|
|||||||
|
|
||||||
-- for Clamity
|
-- for Clamity
|
||||||
incremental_tp.max_instantaneous_tp = {
|
incremental_tp.max_instantaneous_tp = {
|
||||||
x = 6,
|
x = 5,
|
||||||
y = 50,
|
y = 45,
|
||||||
z = 6
|
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 wason=false
|
||||||
local function sign(n)
|
local function sign(n)
|
||||||
if n == 0 then
|
if n == 0 then
|
||||||
@ -21,7 +30,7 @@ local function sign(n)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function max_dist_per(vec, time)
|
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)
|
incremental_tp.fudge)
|
||||||
local nvec = {x = 0, y = 0, z = 0}
|
local nvec = {x = 0, y = 0, z = 0}
|
||||||
nvec.x = sign(vec.x) * math.min(math.abs(vec.x), mitp.x * time)
|
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
|
end
|
||||||
wason=true
|
wason=true
|
||||||
incremental_tp.tpactive=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)
|
minetest.localplayer:set_pos(target)
|
||||||
incremental_tp.tpactive=false
|
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
|
if sfunc then
|
||||||
minetest.after(time, function()
|
minetest.after(time, function()
|
||||||
sfunc(target)
|
sfunc(target)
|
||||||
@ -64,22 +73,31 @@ local function tpstep(target, time, second, variance,sfunc)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local nvec = max_dist_per(vec, intime)
|
local nvec = max_dist_per(vec, intime)
|
||||||
|
local trg=vector.add(pos, nvec)
|
||||||
minetest.localplayer:set_pos(vector.add(pos, nvec))
|
--local safe=ws.find_closest_reachable_airpocket(trg)
|
||||||
|
minetest.localplayer:set_pos(trg)
|
||||||
minetest.after(intime, function()
|
minetest.after(intime, function()
|
||||||
tpstep(target, time, second - intime, variance,sfunc)
|
tpstep(target, time, second - intime, variance,sfunc)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function incremental_tp.tp(target, time, variance)
|
function incremental_tp.tpstep(target, time, variance,sfunc)
|
||||||
if incremental_tp.tpactive then return end
|
if incremental_tp.tpactive then return end
|
||||||
|
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)
|
tpstep(target,time,1,variance)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function incremental_tp.tpafter(target,time,variance,sfunc)
|
function incremental_tp.tpafter(target,time,variance,sfunc)
|
||||||
if incremental_tp.tpactive then return end
|
incremental_tp.tpactive=false
|
||||||
|
minetest.after(time,function()
|
||||||
tpstep(target,time,1,variance,sfunc)
|
tpstep(target,time,1,variance,sfunc)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
if autofly then autofly.register_transport('itp',function(pos,name) incremental_tp.tp(pos,1) end) end
|
if autofly then autofly.register_transport('itp',function(pos,name) incremental_tp.tp(pos,1) end) end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user