Transportation/Teleportation using Bezier Curve

Hello! I am trying to make a teleportation using bezier curve.

So basically, when the player triggers the proximityprompt, it’ll fire and event.
And then, theres many stuffs that happens; invisiblity, particles and i want to add a bezier curve when the player gets transported to the position i have set.

But when i play test, all the scripts works fine but the bezier curve just looks crusty and weird.

this is what i expect it to be like:


here’s a vid of how it looks like in game:
https://gyazo.com/840a756b420f1f1cd6d401f235d76147
local script:

local rs = game:GetService("ReplicatedStorage")
local remoteEvent = rs:WaitForChild("Character"):WaitForChild("characterTeleport")

local proximityPrompt = game.Workspace:WaitForChild("book"):WaitForChild("Plane"):WaitForChild("Attachment"):WaitForChild("ProximityPrompt")
local debounce = false

proximityPrompt.Triggered:Connect(function()
	remoteEvent:FireServer()
end)

script:

local rs = game:GetService("ReplicatedStorage")
local remoteEvent = rs:WaitForChild("Character"):WaitForChild("characterTeleport")

function fade(v)
	for i = 1,20 do
		v.Transparency += 0.1
		task.wait()
	end
end

remoteEvent.OnServerEvent:Connect(function(Player)
	local character = Player.Character
	if not character then		
		return		
	end
	for i, v in pairs(character:GetChildren()) do
		if not v:IsA("BasePart") then 
			continue		
		end
		task.spawn(fade, v)
	end
end)

remoteEvent.OnServerEvent:Connect(function(Player)
	local character = Player.Character
	local humrp = character.HumanoidRootPart
	
	local particle = rs:WaitForChild("Character"):WaitForChild("particle"):Clone()
	particle.Parent = game.Workspace
	particle.CFrame = humrp.CFrame
	
	local runService = game:GetService("RunService")
	runService.Heartbeat:Connect(function()
		particle.Position = humrp.Position
	end)
end)

local function lerp(p0,p1,t)
	return p0*(1-t) + p1*t
end

local function quad(p0,p1,p2, t)
	local l1 = lerp(p0,p1,t)
	local l2 = lerp(p1,p2,t)
	local quad = lerp(l1,l2,t)
	return quad
end

remoteEvent.OnServerEvent:Connect(function(Player)
	local character = Player.Character
	local humrp = character.HumanoidRootPart
	
	local start = game.Workspace:WaitForChild("Part").Position
	local finish = game.Workspace:WaitForChild("Part2").Position
	local middle = (finish - start) + Vector3.new(0,30,0)

	for i = 1, 100 do
		local  t = i/100
		local updated = quad(start,middle,finish,t)
		humrp.Position = updated
		wait(0.01)
	end
end)

Thanks for helping me!

The character isn’t anchored, so in between teleports, the character falls a bit, causing the glitchiness. Additionally, this doesn’t account for wait(0.01) waiting longer than 0.01, although this probably isn’t the cause of the issue. To improve your code, I would suggest doing it on the client, since character movements are automatically replicated to the server.

local Player = game:GetService("Players").LocalPlayer
local RunService = game:GetService("RunService")


local function lerp(p0,p1,t)
	return p0*(1-t) + p1*t
end

local function quad(p0,p1,p2, t)
	local l1 = lerp(p0,p1,t)
	local l2 = lerp(p1,p2,t)
	local quad = lerp(l1,l2,t)
	return quad
end
function teleportPlayer()
	local character = Player.Character
	local humrp = character.HumanoidRootPart

	local start = game.Workspace:WaitForChild("Part").Position
	local finish = game.Workspace:WaitForChild("Part2").Position
	local middle = (finish - start) / 2 + start + Vector3.new(0, 30, 0)

	local t = 0
	while t < 1 do
		character:PivotTo(CFrame.new(quad(start, middle, finish, t)))
		local dt = task.wait()
		t += dt * 0.1
	end
	
end
1 Like

Just to add, there’s no reason to handle proximity triggered in client when you can do it in server

2 Likes

Is the result exactly the same tho?

Yes, the result is exactly the same.

1 Like

Is there any way to do this in a server script? i tried to but the move in a normal script but, it appears to be glitchy
https://gyazo.com/c2a9c44a5d1539f075b17307e126d851

Why are you doing it in a server script?

Because there’s no reason to handle client proximity in the client.