Bézier Curves problem again

after learning how to use Bézier Curves I tried to tween a Image label, yeah didn’t end well.

my script:

function lerp(a, b, c)
	return a + (b - a) * c
end

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

local template1 = script.Parent.Template1
template1:TweenPosition(quadBezier(template1, UDim2.new(0, 0,0.92, 0), UDim2.new(0.496, 0,0.122, 0), UDim2.new(0.496, 0,0.122, 0)))

my error:

  Players.Furkan5E.PlayerGui.ScreenGui.Background.LocalScript:2: attempt to perform arithmetic (mul) on UDim2 and Instance

pretty sure I need convert something but not sure.

1 Like

For the instance probleme, it is template. Look where the t is (it is litteraly your template thingy)

1 Like

template is what I am trying to tween, what?

1 Like

So actually it should be out of the function, just before your function

1 Like

like this? before the function.

local template1 = script.Parent.Template1
function lerp(a, b, c)
	return a + (b - a) * c
end

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

template1:TweenPosition(quadBezier(template1, UDim2.new(0, 0,0.92, 0), UDim2.new(0.496, 0,0.122, 0), UDim2.new(0.496, 0,0.122, 0)))

Edit: same error

1 Like

I am not fully sure but you already have template1:TweenPosition. Why adding the same part into the brackets?

1 Like

t is what’s supposed to be moving, so I added it in

Well i found something that could be usefull:

1 Like

Just pass you UI trhough this function:

local RunService = game:GetService("RunService")

-- // Functions
function lerp(a, b, c)
	return a + (b - a) * c
end

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

	return quad
end

function tweenObject(object, pos1, pos2, pos3)
	
	for i = 1, 100 do
		
		local t = i/100
		
		local XScale = quadBezier(t, pos1.X.Scale, pos2.X.Scale, pos3.X.Scale)
		local YScale = quadBezier(t, pos1.Y.Scale, pos2.Y.Scale, pos3.Y.Scale)

		local XOffset = quadBezier(t, pos1.X.Offset, pos2.X.Offset, pos3.X.Offset)
		local YOffset = quadBezier(t, pos1.Y.Offset, pos2.Y.Offset, pos3.Y.Offset)
		
		object.Position = UDim2.new(XScale, XOffset, YScale, YOffset)
		
		RunService.RenderStepped:Wait()
		
	end
	
end
2 Likes

This sort of worked


the gui stopped half way, nothing in the output

current script:

local RunService = game:GetService("RunService")
local template1 = script.Parent.Template1
function lerp(a, b, c)
	return a + (b - a) * c
end

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

function tweenObject(object, pos1, pos2, pos3)

	for i = 1, 100 do

		local t = i/100

		local XScale = quadBezier(t, pos1.X.Scale, pos2.X.Scale, pos3.X.Scale)
		local YScale = quadBezier(t, pos1.Y.Scale, pos2.Y.Scale, pos3.Y.Scale)

		local XOffset = quadBezier(t, pos1.X.Offset, pos2.X.Offset, pos3.X.Offset)
		local YOffset = quadBezier(t, pos1.Y.Offset, pos2.Y.Offset, pos3.Y.Offset)

		object.Position = UDim2.new(XScale, XOffset, YScale, YOffset)

		RunService.RenderStepped:Wait()

	end

end
tweenObject(template1, UDim2.new(0, 0,0.92, 0), UDim2.new(0.496, 0,0.122, 0), UDim2.new(0.496, 0,0.122, 0))
1 Like

why all 3 of the positions on the same line? it supposed to be pos 0 to pos 1 then from pos 1 to pos 2 but in a curve way.
Bezier2

I still have this problem please help.

Why it doesn't work

When you call tweenObject(), it expects 4 values:
  1. The item you want to tween
  2. UDim2 Start position
  3. UDim2 Curve position
  4. UDim2 End Position

Parameters #3 and #4 are identical, which results in your code-breaking. If you were to change parameter #4 to something else, let’s say UDim2.new(1, 0, 0.122, 0) , we would get a better result.

tweenObject(template1, UDim2.new(0, 0, 0.92, 0), UDim2.new(0.496, 0, 0.122, 0), UDim2.new(1, 0, 0.122, 0)

Why different lines

All 3 positions require to be on different lines to avoid a multiplication error: you can’t multiply an integer with a UDim2 value.

Attempt to perform arithmetic (mul) on number and UDim2
1 Like

OPPS my bad, silly me forgot to change parameter 4, It works like a charm.

1 Like