I’m having issues with my ‘teleport’ system and Camera orientation.
Basically, there’s two Models - Exterior & Interior.
The Exterior can move and rotate willingly whilst the exterior is static.
Below are videos of how the teleporter works -
Video 1: You can see how there’s no issue with transitioning from one area to another as the Camera angle is essentially the same due to the Exterior and Interior portals lining up.
Video 2: The exterior is on a different angle to the Interior, meaning if the Player were to exit, if the Camera weren’t facing the same direction then their walking is offset.
Does anyone have any suggestions of how I can combat this?
You can play with CFrames here. Instead of adjusting the camera, try changing HumanoidRootPart orientation. When entering the room, align root part with door orientation (of course you may have to turn around for 180 degrees at one point).
Player will have set walking direction no matter their previous one when they walk through the door.
Please note that you might have to adjust camera anyway, in case player walks to the right/left (so player’s walk direction vector is perpendicular to camera’s vector). Only applies to third person view.
Different solutions for camera adjusting. This one seems short and simple (under condition that you are free to change CameraType without interrupting your gameplay):
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Attach
CameraType attached means players cannot turn the camera left or right, only up and down. So camera’s orientation depends on humanoid’s orientation. Don’t forget to change type back to default: I think it’s custom .
I’m already rotating the HumanoidRootPart upon Entrance // Exit. However, if the Camera is facing towards the X axis and the Player exits on the Z direction, due to the Camera still facing on X they’ll naturally walk forward to that instead of the direction of the Door.
Though I may look at the changing the CameraType to Attach upon changing between the two locations.
Ideally I’m trying to keep it as smooth as can be, with the transition between camera being seamless. I’ve been picking apart at Portal_Teleportation_Demo but had no such luck in maintaining a persistent angle.
I’ve attached a (very poor for 4am) image. Demonstrating how the Player leaves on one angle and arrives on another; it also illustrates the Camera Position and Angle in correlation to its current Pos.
So, currently if the Player leaves with the Camera behind them and the Exterior is a 90° difference to the exterior, then the Camera will show to the right of the Character and vice versa.
As I see it now, you have two options. The first one is still changing CameraType and the other one is regarding camera CFrame. I am not sure what you mean by making camera transition seamless, at least not more seamless than in the first video. According to camera’s current CFrame you can get the angle at which you wish player to look from after teleportation, and thus achieving the result in the first video. CameraType solution doesn’t affect camera’s Y-axis according to the player, which is an adventage, but at the same time prevents any camera interpolation during transition. Using CFrames gives you more freedom to manipulate with the camera, but gives you a little more work too:
local camera = -- CurrentCamera
local hrp = -- HumanoidRootPart
local hrpPos = hrp.CFrame
camera.CFrame = hrpPos -- custom angles can still be set
Before changing camera CFrame, you can get it’s current CFrame, and use linear interpolation to move between current one and the goal one. I don’t think that’s what you are looking for thought.
Since you want the camera to be in the same position after teleportation as it was before according to the camera subject, you should really set camera CFrame relatively. I think this might be the solution. Try putting the following code in LocalScript and see how it works.
local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild('HumanoidRootPart')
local camera = game.Workspace.CurrentCamera
while (true) do
local offset = hrp.CFrame:PointToObjectSpace(camera.CFrame.Position)
camera.CFrame = CFrame.new(offset)
wait(2)
end
You can implement it in your script. Get camera’s position vector relatively to your portal and apply it after teleportation.