So I’m currently working on a part of a game that I’m working on that involves an infinite hallway. I’m trying to use teleportation to make it look infinite but the transition from teleport-pad to teleport-pad isn’t very smooth.
Does anyone know how I could solve this?
local Teleport = "TeleportPart1"
local Height = 2.5
local TeleportDelay = 2
local CanTeleport = true
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
local XOffset = hit.Parent.HumanoidRootPart.Position.X - script.Parent.Position.X
local ZOffset = hit.Parent.HumanoidRootPart.Position.Z - script.Parent.Position.Z
if CanTeleport == true then
CanTeleport = false
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(script.Parent.Parent[Teleport].CFrame.X + XOffset, script.Parent.Parent[Teleport].CFrame.Y + Height, script.Parent.Parent[Teleport].CFrame.Z + ZOffset)
wait(TeleportDelay)
CanTeleport = true
end
end
end)
Although as D0RYU says above, maintaining the same looking direction as before they teleported will certainly make it more seamless, I’m somewhat skeptical it’s ever going to be totally super smooth to be teleported without even a small loading animation, from the player’s perspective. I’d love to be proven wrong, give his idea a shot and let me know if it’s as smooth as you like! But I have another idea too.
I think you should consider building the infinite hallway out around the player from modular chunks as opposed to teleporting the player. You can delete the chunks as the player gets farther away. Some kind of node graph data structure would be super useful for this job, as you need to make sure the modular pieces of all fit together into a traversable hallway.
If you go this way, try to only make new hallway pieces or destroy old hallway pieces that are far away from the player, so they can’t see it happening. Before you add or delete any hallways, you can also do some simple raycasts out from the player’s head towards the hallway piece. If the casts ever hit any of the parts of a hallway, you’ll know the player can see it and you shouldn’t make the change unless absolutely necessary. (Maybe the player is about to walk into the void and we really need a hallway piece here, but we’d prefer not to make changes while anyone can see)