Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How Can I SMOOTHLY Move a Part?

Asked by 7 years ago

Im trying to learn how I can smoothly move a part. Its like tweening, but for objects. Anyone know how I can do this?

0
You can also use BodyPosition or RocketPropulsion TinyScripter 70 — 7y
0
this doesn't explain a lot, im lost. Can you explain what i should do with the script provided? shootthegame 14 — 7y
0
can i bump? shootthegame 14 — 7y
0
can i bump? shootthegame 14 — 7y

1 answer

Log in to vote
2
Answered by 7 years ago

You can use TweenService to smoothly move and animate baseparts (tween is short for in-between, meaning generating intermediate frames in-between two destinations).

The TweenService instance is a class, so it is done using the GetService method.

local TweenService = game:GetService('TweenService')

You'll need to set the information of the tween first. This defines how long the animation will be, the style and direction, and whatnot. This is done using TweenInfo.new().

local info = TweenInfo.new(
    2,                      --How long the tween is played for (in seconds)
    Enum.EasingStyle.Quad   ,   --The behavior of the tween
    Enum.EasingDirection.Out,   --The direction of the style
    0,                      --How many times the tween will be repeated
    false,                  --Will the tween play in reverse as well?
    0,                      --Delay between each interpolation.
)

You can see how the easing styles act here. Easing directions (In, Out, or InOut) just refers to if the style acts in the beginning, the end, or both of the interpolation.

Next, we need to set the goal, or what properties are going to be tweened. Since this is just moving a part, all we need to do is change the CFrame.

local goal = {CFrame = CFrame.new(0,0,0)} --Set the destination for the part to move to.

Lastly, we just need to create the tween and play it!

local part = workspace.Part --The basepart that will be tweened.

local Tween = TweenService:Create(part,info,goal)

Tween:Play() --Plays the tween. You can also do :Stop() to stop the tween.

That should be it. Here's the code altogether. Hope this helps!

local TweenService = game:GetService('TweenService')
local part = workspace.Part --The basepart that will be tweened.

local info = TweenInfo.new(
    2,                      --How long the tween is played for (in seconds)
    Enum.EasingStyle.Quad   ,   --The behavior of the tween
    Enum.EasingDirection.Out,   --The direction of the style
    0,                      --How many times the tween will be repeated
    false,                  --Will the tween play in reverse as well?
    0,                      --Delay between each interpolation.
)

local goal = {CFrame = CFrame.new(0,0,0)}

local Tween = TweenService:Create(part,info,goal)
Tween:Play() 
0
Good explained already knew it, but goood Pap3rLP 6 — 7y
0
Just say "nice explanation". No need to brag about your knowledge YTRaulByte 389 — 7y
0
Very nice answer! Thank you very much, this worked very well ;) shootthegame 14 — 7y
Ad

Answer this question