Teleport w/ relative Camera?

I’m looking to create a Teleport Pad in which the Player’s camera is constant -
i.e. When the player Teleports from A to B or vice versa, their Camera adjusts accordingly to be how it would on that side.

I want to do this so movement is persistent, so if the Player enters the pad by holding in D (Walking left) then when they come off the Pad they’ll be walking left from the Pad from it’s direction.

I’ve attached a video below depicting the basic function of the Pad, however I’ve used Blue handles to mark the Front Face of the Parts as this is the way the Player will face when they Teleport.

Does anyone have any suggestions?

robloxapp-20231209-2232291.wmv (1.6 MB)

1 Like

Maybe adding hitboxes to see which side of the pad gets hit (hitbox1 → go to certain CFrame orientation)

Maybe get the LookVector of the character’s HumanoidRootPart prior to teleporting it and then use CFrame:lookAt

1 Like

Unfortunately doesn’t give the desired effect -
I had some help last year on an old topic from a previous account where it was made using .CFrame and I’m sure it was :ToMatrix from the desired part however I stupidly stored my projects on a USB that has now corrupted on me. :confused:

1 Like

Oh I can’t help you with this. I can’t do math even if my life relied on it. Hopefully someone else can

Subtract the camera’s position/orientation (separately) from the humanoid’s respective position/orientation, and then once you teleport, you add the stored values to the humanoid’s position and orientation, and the result is your new camera CFrame.

2 Likes

Is there any way of providing a short example of how I can do this? Unsure how I’d take the values seperately and add them separately?

Assuming I understand what you’re looking for correctly, you can just get the camera’s CFrame relative to the root part’s CFrame, then after the teleport, take said relative CFrame and transform it back into world space relative to the root.

local players = game:GetService('Players')

local teleporter = workspace:WaitForChild('Teleporter')

local teleportPart = teleporter:WaitForChild('Teleporter')
local teleportDestination = teleporter:WaitForChild('Destination')

local camera = workspace.CurrentCamera

local deb = false

teleportPart.Touched:Connect(function(otherPart)
	local character: Model = otherPart.Parent
	
	if deb or players:GetPlayerFromCharacter(character) ~= players.LocalPlayer then
		return
	end
	
	deb = true
	
	local root: BasePart = character:WaitForChild('HumanoidRootPart')
	
	local cameraRelative = root.CFrame:ToObjectSpace(camera.CFrame) -- get the camera's CFrame relative to the root CFrame
	
	root:PivotTo(teleportDestination.CFrame + Vector3.new(0, teleportDestination.Size.Y * 0.5 + character:GetExtentsSize().Y * 0.5)) -- the actual teleport
	
	camera.CFrame = root.CFrame:ToWorldSpace(cameraRelative) -- transform back to world space
	
	task.wait(0.1)
	
	deb = false
end)
2 Likes

CFrames. You can use CFrame.LookVector and CFrame.Position, and to set these, you can use CFrame = CFrame.new(Position,Position+Lookvector)

This works nicely!
Only issue is that it doesn’t work when in first person mode; Teleportation doesn’t work the same.

I don’t know if there’s anything that can be done about that. What part isn’t desirable?