From eda8df94eff483bccf1bd75dc33702d491071128 Mon Sep 17 00:00:00 2001 From: ac-minetest Date: Wed, 21 Oct 2015 08:54:15 +0200 Subject: [PATCH] Update init.lua teleports you to target teleporter that best matches your viewing direction ( go where you look ) --- init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/init.lua b/init.lua index 09a9058..b8a44a1 100644 --- a/init.lua +++ b/init.lua @@ -184,6 +184,18 @@ minetest.register_abm({ local positions = teleports:find_nearby(pos, 10) if #positions>0 then local key = math.random(1, #positions) + local dir, dirmag; + local view = player:get_look_dir(); + local dist, distmin; distmin = 99; + for i=1,#positions do -- find teleport closest to where player is looking + dir = {x=positions[i].pos.x-pos.x,y=positions[i].pos.y-pos.y,z=positions[i].pos.z-pos.z}; + dirmag = math.sqrt(dir.x*dir.x+dir.y*dir.y+dir.z*dir.z); if dirmag == 0 then dirmag = 1 end + dir.x=dir.x/dirmag;dir.y=dir.y/dirmag;dir.z=dir.z/dirmag; + dir.x = view.x-dir.x;dir.y = view.y-dir.y;dir.z = view.z-dir.z; + dist = math.sqrt(dir.x*dir.x+dir.y*dir.y+dir.z*dir.z); + if dist 5 then