Alright so in this case I’m trying to generate a quadratic bezier curves (3 control points).
First of all the context for this post is, I’m trying to make a humanoid move to an end point (Goal) but instead of a straight line I’m gonna use a bezier curve to add variation to walking (this time using tween)
The question is, what do i need to do so that i could make the 2nd control points? or the one that will help bend the straight line. The first would be the humanoidrootpart and the last would be the target’s humanoidrootpart as well.
Any help would be appreciated
Current code:
local module = {}
function module.Lerp(t,a,b)
return a + (b-a) * t
end
function module.Quadratic(t,p0,p1,p2)
local l1 = module.Lerp(t,p0,p1)
local l2 = module.Lerp(t,p1,p2)
local quad = module.Lerp(t,l1,l2)
return quad
end
return module
I’m a bit confused as to what you mean by make the second control point. Do you mean how to place it to make a natural feeling walk direction? Or something else?
Nonono like
You see in the picture there’s point 1 which would be the humanoidrootpart for the enemy and point3 which would be the humanoidrootpart for the units/target
The thing i’m struggling is how would you get the second point? or the point 2 i displayed in the picture
local p0 = humanoidRootPart.Position
local p2 = targetHumanoidRootPart.Position
-- Generate second control point
local midpoint = (p0 + p2) / 2
local upOffset = Vector3.new(0, 5, 0)
local p1 = midpoint + upOffset
-- Animate along the Bezier curve
for t = 0, 1, 0.05 do
local position = module.Quadratic(t, p0, p1, p2)
humanoidRootPart.CFrame = CFrame.new(position)
wait()
end
If you want the humanoid to take a slightly arcing path (like a small jump or smooth curve):
local midpoint = (p0 + p2) / 2
local upOffset = Vector3.new(0, 5, 0) -- change 5 to control arc height
local p1 = midpoint + upOffset
That makes the Bezier curve go upward between the two points.
If you want the arc to bend sideways instead of up, replace Vector3.new(0,5,0) with a perpendicular vector.