Change player look direction (yaw) when player exits a portal so that

they have their back to the portal they just exited.
master
Robert Munafo 2015-10-11 23:00:57 -04:00
parent 753463d401
commit 335db88466
5 changed files with 68 additions and 23 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
README.txt~
depends.txt~
init.lua~
.bmdcs-cache.hid

View File

@ -73,6 +73,9 @@ entities so they can be properly reactivated after the player wanders
away and back.
20151009 More refactoring (added op_prtl table which will replace the
old portalgun_portals table)
20151011 When a player is teleported and the exit portal points x+,
x-, z+ or z-, we now set their look direction appropriately so they
have their back to the portal they just emerged from.
TODO - BUG FIXES
@ -88,18 +91,25 @@ should face.
Portals are invisible when seen from behind, even though they still
work.
Set yaw appropriately (using setyaw) for non-player entities
similarly to how I present do set_look_yaw for players. Mobs like rats
and sheep will look more realistic if they emerge head-first from the
portal. As with the player, if the exit portal faces y+ or y-, yaw
should remain unchanged.
Set player's velocity appropriately when exiting portal. On the
forums, Hybrid Dog suggested
(forum.minetest.net/viewtopic.php?f=9&t=12772#p184677) this can be
done by creating an invisible, nonpointable entity (we'd need one per
player) and doing set_attach on it (similarly to how boats work), then
set the object's velocity, and then do a set_detach in a
minetest.after callback to release the player after the engine has
effected the velocity change. But actual experiments with the boat mod
seem to indicate this won't work: the player's velocity returns to 0
as soon as they are detached. So they would need to remain attached as
long as they're still airborne, using a globalstep to detect when the
invisible carrier hits something.
set the object's velocity and acceleration, and then do a set_detach
in a minetest.after callback to release the player after the engine
has effected the velocity change. But actual experiments with the boat
mod seem to indicate this won't work: the player's velocity returns to
0 as soon as they are detached. So they would need to remain attached
as long as they're still airborne, using a globalstep to detect when
the invisible carrier hits something (e.g. any change to x or z
component of velocity).
TODO - COSMETIC

View File

@ -94,7 +94,8 @@ local function portalgun_step_proc(portal, id)
-- check all objects within a radius of 1.5 (it has to be this big
-- to catch players, whose "position" is a point near the feet)
for ii, ob in pairs(minetest.get_objects_inside_radius(pos1, 1.5)) do
if ob:get_luaentity() and ob:get_luaentity().name=="portalgun:portal" then
local ent = ob:get_luaentity()
if ent and ent.name=="portalgun:portal" then
-- this object is the portal itself; ignore
else
-- ======= set velocity then teleport
@ -103,7 +104,13 @@ local function portalgun_step_proc(portal, id)
local y=0
local z=0
if ob:is_player()==false then
if ob:is_player() then
if d2=="x+" then ob:set_look_yaw(math.pi/-2)
elseif d2=="x-" then ob:set_look_yaw(math.pi/2)
elseif d2=="z+" then ob:set_look_yaw(0)
elseif d2=="z-" then ob:set_look_yaw(math.pi)
end
else
-- get object's current velocity.
local v=ob:getvelocity()
@ -122,12 +129,19 @@ local function portalgun_step_proc(portal, id)
v.x = 0
v.y = 0
v.z = 0
if d2=="x+" then v.x=vmag
elseif d2=="x-" then v.x=vmag*-1
elseif d2=="y+" then v.y=vmag
elseif d2=="y-" then v.y=vmag*-1
elseif d2=="z+" then v.z=vmag
elseif d2=="z-" then v.z=vmag*-1 end
if d2=="x+" then
v.x=vmag
elseif d2=="x-" then
v.x=vmag*-1
elseif d2=="y+" then
v.y=vmag
elseif d2=="y-" then
v.y=vmag*-1
elseif d2=="z+" then
v.z=vmag
elseif d2=="z-" then
v.z=vmag*-1
end
ob:setvelocity({x=v.x, y=v.y, z=v.z})
end
@ -357,26 +371,43 @@ local function portal_useproc(itemstack, user, pointed_thing, RMB, remove)
-- the rotation & poss of the portals
if x>0 then portal_dir="x+" cpos.x=(math.floor(cpos.x+ 0.5))+0.504 end
if x<0 then portal_dir="x-" cpos.x=(math.floor(cpos.x+ 0.5))-0.504 end
if y>0 then portal_dir="y+" cpos.y=(math.floor(cpos.y+ 0.5))+0.504 end
if y<0 then portal_dir="y-" cpos.y=(math.floor(cpos.y+ 0.5))-0.504 end
if z>0 then portal_dir="z+" cpos.z=(math.floor(cpos.z+ 0.5))+0.504 end
if z<0 then portal_dir="z-" cpos.z=(math.floor(cpos.z+ 0.5))-0.504 end
if x>0 then
portal_dir="x+"
cpos.x=(math.floor(cpos.x+ 0.5))+0.504
elseif x<0 then
portal_dir="x-"
cpos.x=(math.floor(cpos.x+ 0.5))-0.504
elseif y>0 then
portal_dir="y+"
cpos.y=(math.floor(cpos.y+ 0.5))+0.504
elseif y<0 then
portal_dir="y-"
cpos.y=(math.floor(cpos.y+ 0.5))-0.504
elseif z>0 then
portal_dir="z+"
cpos.z=(math.floor(cpos.z+ 0.5))+0.504
elseif z<0 then
portal_dir="z-"
cpos.z=(math.floor(cpos.z+ 0.5))-0.504
end
local obj = 0
if RMB then
id_p0rtal[id].project=2
id_p0rtal[id].portal2_dir=portal_dir
id_p0rtal[id].portal2_pos=cpos
if id_p0rtal[id].portal2~=0 then id_p0rtal[id].portal2:remove() end
if id_p0rtal[id].portal2~=0 then
id_p0rtal[id].portal2:remove()
end
obj = minetest.env:add_entity(cpos, "portalgun:portal")
id_p0rtal[id].portal2 = obj
else
id_p0rtal[id].project=1
id_p0rtal[id].portal1_dir=portal_dir
id_p0rtal[id].portal1_pos=cpos
if id_p0rtal[id].portal1~=0 then id_p0rtal[id].portal1:remove() end
if id_p0rtal[id].portal1~=0 then
id_p0rtal[id].portal1:remove()
end
obj = minetest.env:add_entity(cpos, "portalgun:portal")
id_p0rtal[id].portal1 = obj
end

1
sounds/.gitignore vendored
View File

@ -6,3 +6,4 @@
800933783.mp3
937891031.mp3
.gitignore~
bmd-ignore.hid

2
textures/.gitignore vendored
View File

@ -1,2 +1,4 @@
orange_middle.png
cyan_middle.png
bmd-ignore.hid
.gitignore~