From 30b17c555aa93d8ebe6aafe762622135b0f7145a Mon Sep 17 00:00:00 2001 From: Och Noe Date: Thu, 23 Sep 2021 14:42:37 +0200 Subject: added '?' for the viewing direction to wp_shift, by Maverick2797 --- init.lua | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/init.lua b/init.lua index 7776885..7cd4c86 100644 --- a/init.lua +++ b/init.lua @@ -249,48 +249,56 @@ end -- new shift with more than one possible shift coordinate -- only the last value for one coordinate is used -local function position_shift2(p) +-- viewing direction (?) added by Maverick2797 on 2021-09-23 +local function position_shift2(p) if not p then return end - + local player = minetest.localplayer local param = p:split(" ") - + local shift = {} shift.x = 0 shift.y = 0 shift.z = 0 - + local vp = 1 - while (vp+1 <= #param ) - do + while (vp+1 <= #param ) do local direction = param[vp] - d = "" - if direction == "x" or direction == "X" then d = "x" end - if direction == "y" or direction == "Y" then d = "y" end - if direction == "z" or direction == "Z" then d = "z" end - if d ~= "" then - distance = tonumber(param[vp+1]) - if not distance then - distance = 0 - end + + local distance = tonumber(param[vp+1]) + if not distance then + distance = 0 + end + + local d = "" + if direction == "x" or direction == "X" then d = "x" end + if direction == "y" or direction == "Y" then d = "y" end + if direction == "z" or direction == "Z" then d = "z" end + if direction == "?" then + --tp according to facing angle + local yaw = player:get_last_look_horizontal() + local pitch = player:get_last_look_vertical() + shift.x = distance*math.cos(yaw)*math.cos(pitch) + shift.z = distance*math.sin(yaw)*math.cos(pitch) + shift.y = distance*math.sin(pitch) + elseif d ~= "" then shift[direction] = distance end vp = vp+2 end - + if shift.x == 0 and shift.y == 0 and shift.z == 0 then return end - - local here = minetest.localplayer:get_pos() - + + local here = player:get_pos() here.x = here.x+shift.x here.y = here.y+shift.y here.z = here.z+shift.z - + -- here.y = here.y - 1 -- correction - + minetest.run_server_chatcommand('teleport', tostring_point(here)) - + end -- cgit v1.2.3