Bezier Curves code problem

Hi, I’m trying to make an NPC throws a molotov, but the middle part of the Bezier is behind the enemy character?

Video:

I need help with this please, I don’t know if my math is wrong or something.

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

function quadBezier(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

local function throw(EnemyHumanoidRootPart)
	local start = BotHrp.Position-- + Vector3.new(0,0,3)
	local finish = EnemyHumanoidRootPart.Position-- + Vector3.new(0,-3,0)
	local middle = (finish - start) + Vector3.new(0,math.random(20,30),0)
	local molotov = Bot["Right Arm"].Molotov:Clone()
	molotov.Transparency = 0
	molotov.Cloth.Transparency = 0
	molotov.Cloth.Fire.Enabled = true
	molotov.Anchored = true
	molotov.Parent = workspace
	
	for i = 1, 100 do
		local t = i/100
		local updated = quadBezier(start,middle,finish,t)
		molotov.Position = updated
		
		local part = Instance.new("Part")
		part.Anchored = true
		part.CanCollide = false
		part.CanQuery = false
		part.Size = Vector3.new(0.5,1000,0.5)
		part.Parent = workspace
		part.Position = finish - start
		--debris:AddItem(part, 5)
		wait()
	end
	
	molotov:Destroy()
end

u have to add 2 vectors and then divide it by 2 to get middle position e.g

local middle = ((finish + start)/2) + Vector3.new(0,math.random(20,30),0)
2 Likes

I’m so stupid thank you so much

1 Like

sorry to say this without any other relation with the post, but im curious on what your working on. looks really cool, share it sometime in the future or once you’re done with it

1 Like

A “real time strategy game” with gacha elements (I love robux)

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