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

How would I make a part move along a certain line when I tell it to?

Asked by 3 years ago

So, I'm trying to make a part that follows a certain path (the path being another part) in the game. I just need the part to slowly move across this line when it's told, and to stop when it's told. I've tried doing certain things with body velocity, and body force, but couldn't seem to make anything work? Every time I did the part either wouldn't move or it wouldn't follow the line it's suppose to follow? Anything helps, just need pointed in the right direction. Thanks.

0
there are so many different ways and I would argue you are already in the right direction. if you want constant movement, use BodyVelocity. if you want gradual, use LineForce. TweenService with CFrames is also popular to move to a specific location. Speedmask 661 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You can use TweenService for it. It is very simple. Here's how it works:

local TS = game:GetService("TweenService")
Part = ____________ --The part you want to move
EndPos = ____________ --The Vector3 position where the part will go

goal = {Position = EndPos} --Setting the goal

local info = TweenInfo.new(
    5, -- The time in seconds it will take to reach the goal
    Enum.EasingStyle.Linear
    Enum.EasingDirection.InOut
    0,
    false,
    0
)

local tween = TS:Create(Part, goal, info)

tween:Play() --Plays the tween animation
0
Line 16 should be local tween = TS:Create(Part, info, goal). Plus your variable naming can be confusing. Dehydrocapsaicin 483 — 3y
0
Why do you need 14 lines for one tween??? Just put the TweenInfo and Goal into the tween CoolBlueJay000 48 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Hello, this is how you do tweening properly.

local TweenService = game:GetService("TweenService")

local part = workspace.Part --of course you're gonna have to put in your part's address
local endPart = workspace.EndPart --put in your end part's address

local tweenInfo = TweenInfo.new() --*
    10,
    Enum.EasingStyle.Linear,
    Enum.EasingDirection.Out,
    0,
    false,
    0
end)

local goal = {
    Position = endPart.Position
}

local tween = TweenService:Create(part, tweenInfo, goal)

tween:Play()

Use tween:Pause() to freeze the part's position and tween:Play() to continue.

Resources that may help: https://developer.roblox.com/en-us/api-reference/class/TweenService https://developer.roblox.com/en-us/api-reference/datatype/TweenInfo* https://developer.roblox.com/en-us/api-reference/function/TweenBase/Pause

Answer this question