Hello, i am looking for a method that will allow me to curve while Tweening Objects
For Example, I want to move Object A to B using TweenService, but if i do that, it will be pretty straight foward, while i want it like move i little bit to the right and something like that.
That would require you to make your own custom function, that creates interpolation between cframes. At the same time it would use a mathematical formula for a bezier curve.
I believe this person has made a very good explanation of how that works, by recreating a blade ball’s ball system.
There are lots of different possible curves you could use, the simplest being a circular arc, since you would have an easy way to control how far it gets from the straight-line path, just by picking the radius of the circle. And the motion would be constant velocity by tweening the rotation angle linearly. If you need the lateral deflection to be more than half the distance between A and B, you could just stretch the circle into a ellipse.
But there are lots of other curves you too, the choice depends a lot on how you want it to look.
I’ll give a simple example of how you can make a bezier that takes a random point in the middle of the trajectory and tilts it a little to the side
local PointA = Vector3.new()
local PointB = Vector3.new(0, 0, 10)
local Part = workspace.Part
local Magnitude = (PointA - PointB).Magnitude
local MidPosition = CFrame.new(PointA, PointB) * CFrame.new(0, 0, -Magnitude) * CFrame.new(-math.random(Magnitude / 2), math.random(Magnitude / 2)).Position
local function Lerp(a, b, c)
return a + (b - a) * c
end
local function QuadBezier (StartPosition, MidPosition, EndPosition, Offset)
local L1 = Lerp(StartPosition, MidPosition, Offset)
local L2 = Lerp(MidPosition, EndPosition, Offset)
local QuadBezier = Lerp(L1, L2, Offset)
return QuadBezier
end
for Index = 1, 10 do
local CurrentPosition = QuadBezier(PointA, MidPosition, PointB, Index / 10)
local PositionTween = game.TweenService:Create(Part, TweenInfo.new(.1), {Position =
CurrentPosition})
PositionTween:Play()
PositionTween.Completed:Wait()
end
There may be some errors because I did it without using a code editor and I’m sleepy