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