So I’m in the process of recreating the game Portal and I have most of the portal mechanics sorted out, but there’s been one major issue throughout developing it - the camera needs to face the correct direction when you pass through portals.
So I made some code here, which basically gets the difference between the two portals angles and applies that onto the camera’s CFrame. This works, but there’s an issue:
diff = portals.OrangePortal.ViewportCenter.Orientation -
portals.BluePortal.ViewportCenter.Orientation
-- Get the difference between the orange and blue portal angles, relative to orange
ry = diff.Y
local angleDiff = CFrame.Angles(0, math.rad(ry), 0) -- convert to rad
game.Workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * angleDiff
-- Apply this to the player's camera
The issue here is that when you leave the portal, your Y angle will be correct, but the Vertical angle (I think this is X?) is inverted, therefore entering a portal facing down will make you exit facing upwards instead. There is also another issue in that this only works if both portals have a difference of a multiple of 180 (e.g. blue 180 and orange 180), if one is 90 degrees to another the player will face as if the portals are 180 degrees to one another.
I’ve tried inverting the degrees, setting the other angles to 0 (as seen in the code) and just negating them, but every time the result is the same: your vertical angle is wrong.
How can I make it so that the player will face the correct way when exiting a portal?
I would post a video but the DevForum never lets me do that, so… if you know why let me know and I’ll try again I suppose