# Bezier Curve Humanoid Tween

So, I am making a tds game and I want the smooth 90 degree turn around “waypoints” on the path, like how TDS X does it

My pretty simple system works by going through the folder’s Children by numerical order in their names, I have tried doing that for the bezier curve but it didn’t go so well.

Please note that I don’t have much knowledge of bezier curves.

Enemy Script:

``````local Tween = game:GetService("TweenService")
local enemy = workspace.Model
local Path = workspace.Map.Movement
local Spawn = workspace.Map.Movement.Spawn

local speed = 8
local rotspeed = 1

function SpawnEnemy()
local entity = enemy:Clone()
entity.HumanoidRootPart.CFrame = Spawn.CFrame
entity.Parent = workspace
MoveEnemy(entity)
end

function MoveEnemy(entity)
for waypoint=1, #Path:GetChildren() do
local Walking = Tween:Create(entity.HumanoidRootPart, TweenInfo.new((entity.HumanoidRootPart.Position - Path[waypoint].Position).Magnitude/speed, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {CFrame = Path[waypoint].CFrame})
Walking:Play()
Walking.Completed:Wait()
end
end

while true do
SpawnEnemy()
wait(2)
end
``````

Bezier Script:

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

local l1 = lerp(p0, p1, t)

local l2 = lerp(p1, p2, t)

local quad = lerp(l1, l2, t)

end

local PointA = workspace.Map.Movement[1]
local PointB = workspace.Map.Movement[2]
local PointC = workspace.Map.Movement[3]

for i=0, 1, .1 do
for j=1,10 do
local part = Instance.new("Part")
part.Anchored = true
part.Name = ""..tostring(j)
part.Transparency = 0
part.Color = Color3.fromRGB(255, 191, 0)
part.Size = Vector3.new(.5,.5,.5)
part.CFrame = CFrame.new(quadBezier(i, PointA.Position, PointB.Position, PointC.Position))
part.Parent = workspace.Map.Movement
end

end

``````

the bezier script is based on this video

Help would be appreciated
And also note that my knowledge in lua is not great, more less Roblox’s LuaU, but it has been easy going with my knowledge in c++ and java

I believe TD X uses some hacky maths to have smooth turns. The programmer Atrazine who works for TD X has said that he had used maths to make it turn smoothly. Though I’m not too sure what maths you could use instead of bezier.

For more advanced methods I suggest you could Hermite Splines which are a bit similar to bezier.

though, this is a necropost, thanks for it anyway!

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