FE2 Zipline Changing Speed, again

Hello everyone! This one is a bit different to the other topic I made.
This time, it changes depending on the size of the zipline. Here is the clip:

Script:

local speed = (points[1].Position - points[#points].Position).Magnitude * 1.5
	
	local posPoints = {}
	for i=1, #points do
		table.insert(posPoints, points[i].Position)
	end
	local inc = (1/(89))
	for t = 0, 1 - inc, inc do
		local pos = Bezier.GetBezierPoint(t, unpack(posPoints))
		local nextPos = Bezier.GetBezierPoint(t + inc, unpack(posPoints))
		local Distance = (pos - nextPos).magnitude
		local this = CFrame.new(pos, nextPos) * CFrame.new(0, 0, -Distance / 2)
		bodyPos.Position = this.Position - Vector3.new(0,2,0)
		bodyGy.CFrame = this - Vector3.new(0,2,0)
		part.CFrame = this
		game:GetService("RunService").RenderStepped:Wait()
	end

Can someone help???
p.s. speed variable doesnt change anything

2 Likes

Just a guess, but wouldn’t checking the total length between the startpoint and the endpoint and then doing some math work? here is an example that you should give a try:

local Multiplier = 1.5  -- Adjust this value to change the speed

local posPoints = {}
for i = 1, #points do
    table.insert(posPoints, points[i].Position)
end

local length = 0
for i = 1, #posPoints - 1 do
    length = length + (posPoints[i] - posPoints[i + 1]).Magnitude
end

local speed = (posPoints[1] - posPoints[#posPoints]).Magnitude * Multiplier
local inc = speed / length

for t = 0, 1 - inc, inc do

    local pos = Bezier.GetBezierPoint(t, unpack(posPoints))
    local nextPos = Bezier.GetBezierPoint(t + inc, unpack(posPoints))
    local Distance = (pos - nextPos).magnitude
    local this = CFrame.new(pos, nextPos) * CFrame.new(0, 0, -Distance / 2)
    
    bodyPos.Position = this.Position - Vector3.new(0, 2, 0)
    bodyGy.CFrame = this - Vector3.new(0, 2, 0)
    part.CFrame = this
    
    game:GetService("RunService").RenderStepped:Wait()

end

Doesn’t change anything.

btw here is the “GetBezierPoint” function:

function module.GetBezierPoint(T, ...)
	local Points = {...}

	while (#Points > 1) do
		for i = 1, #Points - 1 do
			Points[i] = Lerp(Points[i], Points[i + 1], T)
		end

		Points[#Points] = nil
	end

	return Points[1]
end

Now I am not moving and/or being flung.

honestly, my recommendation would just be to use bhristt’s bezier module, it has custom functions that allow you to do tweens with constant speed, thats what i used, really cool module.

Bhristt’s Bezier Curve Module (Tween support) - Resources / Community Resources - Developer Forum | Roblox

How could I use it in this script? I am confused.

Old Bezier Module:

local module = {}


function Lerp(P0, P1, T)
	return (1 - T) * P0 + T * P1
end

function module.GetBezierPoint(T, ...)
	local Points = {...}

	while (#Points > 1) do
		for i = 1, #Points - 1 do
			Points[i] = Lerp(Points[i], Points[i + 1], T)
		end

		Points[#Points] = nil
	end

	return Points[1]
end

function createPart(Point, NextPoint, Parent)
	local ZiplinePart = Instance.new("Part")

	ZiplinePart.Anchored = true
	ZiplinePart.Size = Vector3.new(0.25, 0.25, (Point - NextPoint).Magnitude)
	ZiplinePart.CFrame = CFrame.lookAt(Point, NextPoint, Vector3.new(0, 1, 0)) * CFrame.new(0, 0, ZiplinePart.Size.Z / -2)
	ZiplinePart.Material = Enum.Material.Grass
	ZiplinePart.Color = Color3.new(0, 0, 0)
	ZiplinePart.Parent = Parent
	ZiplinePart.CanCollide = false

	return ZiplinePart
end

function module.new(par, ...)
	local points = {...}
	local posPoints = {}
	for i=1, #points do
		table.insert(posPoints, points[i].Position)
	end
	
	local inc = (1 / 40)
	
	for i = 0, 1.025 - inc, inc do
		local Point = module.GetBezierPoint(i, unpack(posPoints))
		local NextPoint = module.GetBezierPoint(i + inc, unpack(posPoints))
		createPart(Point, NextPoint, par)
	end
end

return module

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.