This commit is contained in:
arpruss 2015-09-25 23:08:53 -05:00
parent 8953e9e98c
commit fbc2282deb

View File

@ -46,7 +46,7 @@ function getplayer(id)
end
function handle_entity(cmd, id, args)
entity = getplayer(id)
local entity = getplayer(id)
if cmd == "getPos" then
local pos = entity:getpos()
return ""..(-pos.x)..","..(pos.y)..","..(pos.z)
@ -59,6 +59,30 @@ function handle_entity(cmd, id, args)
elseif cmd == "getDirection" then
local dir = entity:get_look_dir()
return ""..(-dir.x)..","..(dir.y)..","..(dir.z)
elseif cmd == "setPitch" then
-- TODO: For mysterious reasons, set_look_pitch() and get_look_pitch()
-- values are opposite sign, so we don't negate here. Ideally, the mod
-- would detect this to make sure that if it's fixed in the next version
-- this wouldn't be an issue.
entity:set_look_pitch(tonumber(args[1]) * math.pi / 180)
elseif cmd == "setRotation" then
-- TODO: For mysterious reasons, set_look_yaw() and get_look_yaw()
-- values differ by pi/2. Ideally, the mod
-- would detect this to make sure that if it's fixed in the next version
-- this wouldn't be an issue.
entity:set_look_yaw((-tonumber(args[1])) * math.pi / 180)
elseif cmd == "setDirection" then
-- TODO: Fix set_look_yaw() and get_look_yaw() compensation.
local x = tonumber(args[1])
local y = tonumber(args[2])
local z = tonumber(args[3])
local xz = math.sqrt(x*x+z*z)
if xz >= 1e-9 then
entity:set_look_yaw(- math.atan2(-x,z))
end
if x*x + y*y + z*z >= 1e-18 then
entity:set_look_pitch(math.atan2(-y, xz))
end
end
return nil
end