added '?' for the viewing direction to wp_shift, by Maverick2797

master
Och Noe 2021-09-23 14:42:37 +02:00
parent 274bc7abbf
commit 30b17c555a
1 changed files with 30 additions and 22 deletions

View File

@ -249,9 +249,10 @@ end
-- new shift with more than one possible shift coordinate -- new shift with more than one possible shift coordinate
-- only the last value for one coordinate is used -- only the last value for one coordinate is used
-- viewing direction (?) added by Maverick2797 on 2021-09-23
local function position_shift2(p) local function position_shift2(p)
if not p then return end if not p then return end
local player = minetest.localplayer
local param = p:split(" ") local param = p:split(" ")
local shift = {} local shift = {}
@ -260,18 +261,26 @@ local function position_shift2(p)
shift.z = 0 shift.z = 0
local vp = 1 local vp = 1
while (vp+1 <= #param ) while (vp+1 <= #param ) do
do
local direction = param[vp] local direction = param[vp]
d = ""
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 == "x" or direction == "X" then d = "x" end
if direction == "y" or direction == "Y" then d = "y" end if direction == "y" or direction == "Y" then d = "y" end
if direction == "z" or direction == "Z" then d = "z" end if direction == "z" or direction == "Z" then d = "z" end
if d ~= "" then if direction == "?" then
distance = tonumber(param[vp+1]) --tp according to facing angle
if not distance then local yaw = player:get_last_look_horizontal()
distance = 0 local pitch = player:get_last_look_vertical()
end 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 shift[direction] = distance
end end
vp = vp+2 vp = vp+2
@ -281,8 +290,7 @@ local function position_shift2(p)
return return
end end
local here = minetest.localplayer:get_pos() local here = player:get_pos()
here.x = here.x+shift.x here.x = here.x+shift.x
here.y = here.y+shift.y here.y = here.y+shift.y
here.z = here.z+shift.z here.z = here.z+shift.z