# Tween in a curve

Hello. I want to tween a plane (let’s just use a part for now) flying really fast, but not really in a straight line, but sort of in a curve, like this:

Any ideas on how to achieve this? Keep in mind that the part has to behave like a plane in that faces the direction it’s going

this requires math, it shouldn’t be to complicated.

``````local startpos = Vector3.new(0,10,0)
local endpos= Vector3.new(10,10,0)

local distance = (startpos - endpos).Magnitude
local currentPos = Vector3.new(5,10,0) -- halfway

local DistanceY = 5 -- amount of studs the plane's gets to reach.

local half = distance/2
local Yposition = math.abs(currentPos.X/half) * DistanceY
local Position = Vector3.new(Xposition,0,0)
``````

(there might be errors, I made it quickly)

1 Like

What is “Xposition” on the last line supposed to be?

Also, you never really explained to me what I’m supposed to do with these exactly.

i didn’t calculated Xposition but you don’t really need it you can use a body velocity or whatsoever

Please elaborate. I’m having a hard time understanding

If you need something to travel in a physics like manner then you should use a physics related instance, like the BodyMover instances.

These have been superseded by VectorForce instances if you wish to use those instead.

have you tried bezier curves? there’s api for it

I am aware. I don’t really know how I’m going to use one or where to even start.

I have learned that Roblox tween don’t really support such thing so thats out of the question.

you can still use tweenservice:getvalue() to tween in a bezier curve

it would look something like this:

t - the progression in the bezier (0 start, 1 finish)
p0 - the start position
p1 - the mid position
p2 - the end position

``````local function Bezier(t, p0, p1, p2)
return (1 - t) ^ 2 * p0 + 2 * (1 - t) * t * p1 + t ^ 2 * p2
end

for Time = 0, 1, 0.005 do
Part.Position = Bezier(Time, StartVector3, TheMidPointVector, EndVector3)
end
``````

or you can also use :SetPrimaryPartCFrame() if you’re trying to set a model’s position as long as you convert the bezier result to a cframe

and in order to be able to create a bezier tween you’ll use tweenservice:getvalue()

``````local TweenService = game:GetService("TweenService")

local function Bezier(t, p0, p1, p2)
return (1 - t) ^ 2 * p0 + 2 * (1 - t) * t * p1 + t ^ 2 * p2
end

for Time = 0, 1, 0.005 do
Part.Position = Bezier(TweenService:GetValue(Time, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), StartVector3, TheMidPointVector, EndVector3)