you could calculate the control point as the midpoint between the start and end points, and then offset it by a certain distance in the direction perpendicular to the line between the start and end points.
Here’s a simple example:
local function calculateControlPoint(startPoint, endPoint, offset)
local midpoint = (startPoint + endPoint) / 2
local direction = (endPoint - startPoint).Unit
local perpendicular = Vector3.new(-direction.Z, 0, direction.X) -- this gives a vector perpendicular to the direction vector
local controlPoint = midpoint + perpendicular * offset
return controlPoint
end
local startPoint = Vector3.new(0, 0, 0)
local endPoint = Vector3.new(10, 0, 10)
local offset = 5 -- adjust this value to change the "sharpness" of the turn
local controlPoint = calculateControlPoint(startPoint, endPoint, offset)
This script calculates the control point as the midpoint between the start and end points, and then offsets it by a certain distance in the direction perpendicular to the line between the start and end points. The offset
variable determines how “sharp” the turn is.
You can then use this control point to create your curve as before:
local curve = createCurve(startPoint, endPoint, controlPoint, resolution)
So this it how it would look like:
local function lerp(a, b, t)
return a + (b - a) * t
end
local function createCurve(startPoint, endPoint, controlPoint, resolution)
local curve = {}
for t = 0, 1, 1/resolution do
local A = lerp(startPoint, controlPoint, t)
local B = lerp(controlPoint, endPoint, t)
local C = lerp(A, B, t)
table.insert(curve, C)
end
return curve
end
local function calculateControlPoint(startPoint, endPoint, offset)
local midpoint = (startPoint + endPoint) / 2
local direction = (endPoint - startPoint).Unit
local perpendicular = Vector3.new(-direction.Z, 0, direction.X) -- this gives a vector perpendicular to the direction vector
local controlPoint = midpoint + perpendicular * offset
return controlPoint
end
local startPoint = Vector3.new(0, 0, 0)
local endPoint = Vector3.new(10, 0, 10)
local offset = 5 -- adjust this value to change the "sharpness" of the turn
local resolution = 100
local controlPoint = calculateControlPoint(startPoint, endPoint, offset)
local curve = createCurve(startPoint, endPoint, controlPoint, resolution)
local part = game.Workspace.Part
for i, point in ipairs(curve) do
part.CFrame = CFrame.new(point)
wait(0.1)
end
This will calculate the control point based on the start and end points and the offset. Then it creates a curve using these points, and to visualize it, it will move a part along this curve
Still take note that this is a basic example.