I would like to turn an NPC, that follows a path (tower defence game). The angles are arbitrary angles, and I would like it to be able to turn smoothly on multiple different angle types (90, 45, 12 etc).
This is the image of the desired curve. As you can see there is one point in the middle and it is a smooth turn. Could i use lerp or any other math function or formula. REFERENCES:
EDIT
So far, I have this code that works like this:
CODE:
local RADIUS = 4
local part = Instance.new("Part")
part.Size = Vector3.new(1, 1, 1)
part.Anchored = true
part.Parent = workspace
local cOrigin = Vector3.new(5, 10, 5)
local currentAngle_RAD = 0
game:GetService("RunService").RenderStepped:Connect(function()
if currentAngle_RAD >= math.rad(360) then
currentAngle_RAD = 0
end
local x = cOrigin.X + RADIUS * math.cos(currentAngle_RAD)
local z = cOrigin.Z + RADIUS * math.sin(currentAngle_RAD)
part.Position = Vector3.new(x, cOrigin.Y, z)
currentAngle_RAD += math.rad(3)
end)
VIDEO:
if anyone could change this code so it can work for 45 degree rotations / arbitrary angles that would be lovely!
EDIT
This is what bezier curves with 3 points would look like