im trying to make the part move to a certain cframe but i want it to curve instead of just moving in a straight line towards it.
Im trying to make the part move towards where the mouse is pointing, but I don’t want it moving in a straight line towards it, i want it to curve.
the code is basic but yh
mouseinfo[2] is the position of the mouse
local mouseinfo = plr.Character.GetMouse:InvokeClient(plr)
local Part = Instance.new(“Part”,workspace)
Part.Anchored = true
Part.CanCollide = false
Part.CFrame = plr.Character.HumanoidRootPart.CFrame
wait(.5)
Part.CFrame = CFrame.new(mouseinfo[2])
1 Like
You can use Bezier curves ← Linked to Roblox dev article
I made a curve creating script myself to assist with some building so Ill put it in my reply for you to use or pull apart as you wish.
My Curve Script
--Minis Curve Creating Script (UnderDev)
--https://developer.roblox.com/en-us/articles/Bezier-curves
-- T is a decimal below 1, 1 means curve is completed
--So smaller intervals means more points and smoother creation
--P1 Is midpoint
--P0 and P2 are the start and finish
--Uses Pythag and current position + %Complete
--V1
function lerp(a,b,c)
return a + (b - a) * c
end
--Lerps All the points
function CurvePoint(p0,p1,p2,t)
t = t
--LERP X
Xl1 = lerp(p0.X, p1.X, t)
Xl2 = lerp(p1.X, p2.X, t)
XLerp = lerp(Xl1, Xl2, t)
--LERP Y
Yl1 = lerp(p0.Y, p1.Y, t)
Yl2 = lerp(p1.Y, p2.Y, t)
YLerp = lerp(Yl1, Yl2, t)
--LERP Z
Zl1 = lerp(p0.Z, p1.Z, t)
Zl2 = lerp(p1.Z, p2.Z, t)
ZLerp = lerp(Zl1, Zl2, t)
Pos = Vector3.new(XLerp,YLerp,ZLerp)
return Pos
end
-- Simplify Curve
-- T should usually be 0
function CreateCurve(p0,p1,p2,t,Inc)
Points = {}
t = t
LoopCount = 0
while t < 0.99 do
CurvePoint(p0,p1,p2,t)
Points[LoopCount] = CurvePoint(p0,p1,p2,t)
--Keeps Track Of Progress
LoopCount = LoopCount + 1
t = LoopCount * Inc
end
return Points
end
function test()
print("test")
p0 = game.Workspace.p0.Position
p1 = game.Workspace.p1.Position
p2 = game.Workspace.p2.Position
t = 0
Inc = 0.02
Curve = CreateCurve(p0,p1,p2,t,Inc)
for i = 1,#Curve do
Point = Curve[i]
NewPart = Instance.new("Part",game.Workspace.Test)
NewPart.Size = Vector3.new(1,1,1)
NewPart.Transparency = 0.5
NewPart.Anchored = true
NewPart.Position = Point
wait(0.1)
end
end
test()