You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to make a script that can generate a simple bezier curve path from between 2 nodes which also takes into account the direction and orientation of each node. -
What is the issue? Include screenshots / videos if possible!
This is an image of a pre made path that I placed down (not the orientation indicators and their direction)
My current code creates a bezier curve path which doesnt take into account the orientation indicators shown in the first image.
As well, if you look closely at the individual parts, there are gaps between them due to incorrect sizing of the lengths of each part.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
For the first issue regarding taking into account the orientation, I haven’t tried anything and I’ve been looking for other solution on the developer hub but no such luck
For the second issue regarding the gaps, I tried to create a script that calculates the distance between two outer edges (the gap between two individual parts) and then calculates the desired size to scale them, but that didn’t work and the sizing was incorrect.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
here is the code for the bezier curve path main script
local interpolation = require(script.Interpolation)
local curve = workspace.curve
local points = workspace.points
local startP
local midP
local endP
local last
local function CalculateProperties(part, pos1, pos2)
part.Position = pos2 + Vector3.new(0,0,0)
local diff = (pos2 - pos1)
local angleY = math.deg(math.atan2(diff.X, diff.Z))
part.Size = Vector3.new(part.Size.X, part.Size.Y, diff.Magnitude)
part.Orientation = Vector3.new(0, angleY, 0)
part.Parent = curve
end
task.wait(5)
while true do
curve:ClearAllChildren()
last = nil
startP = points.node1.Position
midP = points.mid.Position
endP = points.node2.Position
for t = 0, 1, 0.01 do
local newPos = interpolation.QuadBezier(startP, midP, endP, t)
local part = game.ReplicatedStorage.part:Clone()
part.CanCollide = false
part.Anchored = true
part.TopSurface = Enum.SurfaceType.SmoothNoOutlines
if last then
CalculateProperties(part, last, newPos)
end
last = newPos
task.wait()
end
task.wait(3)
end
here is the interpolation module.
local interpolation = {}
function interpolation.Lerp(a, b, t)
return (1 - t) * a + t * b
end
function interpolation.QuadBezier(a, b, c, t)
return (1 - t)^2*a + 2*(1 - t)*t*b + t^2*c
end
function interpolation.CubicBezier(a, b, c, d, t)
end
return interpolation