Im trying to make a Script where the part rotates while curving around a part but the rotating is being stupid
local TS = game:GetService("TweenService") local rarm = workspace.arm local root = workspace.rot rarm.Transparency = 0.7 rarm.Orientation = Vector3.new(45, 0.09, -19.88) rarm:ClearAllChildren() rarm.Anchored = true rarm.Position = root.Position + Vector3.new(-3, -3, 2) function lerp(a, b, t) return a + (b - a) * t end function cubicBezier(t, p0, p1, p2, p3) local l1 = lerp(p0, p1, t) local l2 = lerp(p1, p2, t) local l3 = lerp(p2, p3, t) local a = lerp(l1, l2, t) local b = lerp(l2, l3, t) local cubic = lerp(a, b, t) return cubic end local f1 = root.Position + -root.CFrame.LookVector*2 + -root.CFrame.upVector*3 + -root.CFrame.RightVector*3 local f2 = root.Position + root.Position + root.CFrame.LookVector*.8 + -root.CFrame.upVector*.15 + -root.CFrame.RightVector*5.5 local f3 = root.Position + root.CFrame.LookVector*5.25 + root.CFrame.upVector*.5 + -root.CFrame.RightVector*2.75 local f4 = root.Position + root.CFrame.LookVector*7.5 + root.CFrame.upVector*1.3 + root.CFrame.RightVector*1.5 spawn(function() for t = 0,1,.08 do local curve = cubicBezier(t,f1,f2,f3,f4) rarm.CFrame = CFrame.new(curve) rarm.Orientation = rarm.Orientation + Vector3.new(0,0,5) game:GetService("RunService").Heartbeat:Wait() end; end)
this my code
I see that you're incrementing the rotation of the object, this may cause issues when the rotation doesn't change linearly (which it doesn't in a cubic bezier curve).
One solution would be to interpolate CFrames instead of Vector3s when creating the Bézier curve, since CFrames have a rotation property. You can use CFrame:Lerp()
to interpolate between CFrames.
local TS = game:GetService("TweenService") local rarm = workspace.arm local root = workspace.rot rarm.Transparency = 0.7 rarm.Orientation = Vector3.new(22.52, -135.9, -69.64) rarm.CFrame = root.CFrame + -root.CFrame.LookVector*2 + -root.CFrame.upVector*3 + -root.CFrame.RightVector*3 rarm:ClearAllChildren() rarm.Anchored = true function lerp(a, b, t) return a + (b - a) * t end function cubicBezier(t, p0, p1, p2, p3) local l1 = lerp(p0, p1, t) local l2 = lerp(p1, p2, t) local l3 = lerp(p2, p3, t) local a = lerp(l1, l2, t) local b = lerp(l2, l3, t) local cubic = lerp(a, b, t) return cubic end local f1 = root.Position + -root.CFrame.LookVector*2 + -root.CFrame.upVector*3 + -root.CFrame.RightVector*3 * CFrame.Angles(math.rad(22.52),math.rad(-135.9),math.rad(-69.64)) local f2 = root.Position + root.CFrame.LookVector*.8 + -root.CFrame.upVector*.15 + -root.CFrame.RightVector*5.5 * CFrame.Angles(math.rad(22.52),math.rad(-135.9),math.rad(-69.64)) local f3 = root.Position + root.CFrame.LookVector*5.25 + root.CFrame.upVector*.5 + -root.CFrame.RightVector*2.75 * CFrame.Angles(math.rad(22.52),math.rad(-135.9),math.rad(-69.64)) local f4 = root.Position + root.CFrame.LookVector*7.5 + root.CFrame.upVector*1.3 + root.CFrame.RightVector*1.5 * CFrame.Angles(math.rad(22.52),math.rad(-135.9),math.rad(-69.64)) spawn(function() for t = 0,1,.08 do local curve = cubicBezier(t,f1,f2,f3,f4) rarm.Position = curve game:GetService("RunService").Heartbeat:Wait() end; end)
something like this Vinceberget?