Infinite Hallway

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)

this is the game:

1 Like

I would change the position instead, that way the player is still facing the same way as before

local Parent = script.Parent
local Teleport = Parent.Parent["TeleportPart1"]

local Height = 2.5
local TeleportDelay = 2
local CanTeleport = true

function Offset(HumanoidRootPart, Axis)
    return HumanoidRootPart.Position[Axis] - Parent.Position[Axis]
end

script.Parent.Touched:Connect(function(hit)
    local HumanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")

    if HumanoidRootPart and CanTeleport then
        CanTeleport = false

        HumanoidRootPart.Position = Vector3.new(
            Teleport.Position.X + Offset(HumanoidRootPart, "X"),
            Teleport.Position.Y + Height,
            Teleport.Position.Z + Offset(HumanoidRootPart, "Z")
        )

        task.wait(TeleportDelay)
        CanTeleport = true
    end
end)
1 Like

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)

1 Like

messing with the hallway itself will definitely work
might take time to make it work compared to teleporting the character, but it should be worth it

I just published it with your script but it still ain’t smooth for some reason

you should try @shinji_ikari8‘s idea
that should be more smooth

how can I find his idea?
is it a game on his Roblox account or does he have a dev forum too?

scroll up, they replied on this post

the problem with that is that this hallway has to be connected to other parts of the map so the chunks idea isn’t something I can do