Leap using bezier curves?

I’m trying to make a leap ability using bezier curves and I achieved what I wanted to do, however, I’ve only been able to do it using parts and so I have pretty bad code that I can’t figure out how to improve.

UIS.InputBegan:Connect(function(inputObject, gameProcessed)
	if inputObject.KeyCode == Enum.KeyCode.One then		
		local part1 = Instance.new("Part")
		part1.Anchored = true 
		part1.CanCollide = false 
		part1.Color = Color3.fromRGB(255,191,0)
		part1.Size = Vector3.new(.5,.5,.5)
		part1.Name = "PointA"
		part1.Transparency = 1
		part1.Parent = workspace
		
		local part2 = Instance.new("Part")
		part2.Anchored = true 
		part2.CanCollide = false 
		part2.Color = Color3.fromRGB(255,191,0)
		part2.Size = Vector3.new(.5,.5,.5)
		part2.Name = "PointB"
		part2.Transparency = 1
		part2.Parent = workspace
		
		local part3 = Instance.new("Part")
		part3.Anchored = true 
		part3.CanCollide = false 
		part3.Color = Color3.fromRGB(255,191,0)
		part3.Size = Vector3.new(.5,.5,.5)
		part3.Name = "PointC"
		part3.Transparency = 1
		part3.Parent = workspace
		
		local pointA = root.CFrame
		local pointC = root.CFrame*CFrame.new(0,0,-30)
		
		part1.CFrame = pointA
		part3.CFrame = pointC
		
		local pointB = part1.CFrame:lerp(part3.CFrame,0.5) * CFrame.new(0,5,0)
		part2.CFrame = pointB
		
		for i = 0, 1, .1 do
			root.CFrame = CFrame.new(Util:QuadraticBezier(i,part1.Position,part2.Position,part3.Position))
			task.wait(.01)
		end
	end
end)

This is the result

2 Likes

Is your question just how to do this without creating new parts?

Because you can store CFrames as variables and use them directly:

UIS.InputBegan:Connect(function(inputObject, gameProcessed)
	if inputObject.KeyCode == Enum.KeyCode.One then		
		local pointA = root.CFrame
		local pointC = pointA*CFrame.new(0,0,-30)
		
		local pointB = pointA:lerp(pointC,0.5) * CFrame.new(0,5,0)
		
		for i = 0, 1, .1 do
			root.CFrame = CFrame.new(Util:QuadraticBezier(i,pointA.Position,pointB.Position,pointC.Position))
			task.wait(.01)
		end
	end
end)
2 Likes

I tried doing something very similar to this, but I guess I did something wrong with the calculation because it wasn’t working. Anyways, thanks this worked.

2 Likes