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

Using CFrame to move an object to a position?

Asked by 3 years ago

I have seen people using CFrames to move an object to another objects position but actually having it move and not just teleport. I was wondering how this works. You can see it is used here.

0
You can use TweenService if you want to move parts. ArsonMcFlames 363 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Use TweenService! Tweening is used for interpolating almost any numeric property of certain objects. In your case, I'm assuming, a part.

So here's how it goes;

local TweenService = game:GetService("TweenService") --gets tween service

local part = workspace.Part --gets the part (change it to your own part's address)

local tweenInfo = TweenInfo.new( --how we want our tween to play
    1, --how fast the tween is (in seconds)
    Enum.EasingStyle.Linear, --easing style
    Enum.EasingDirection.Out, --easing direction
    0, --no. of times the tween will repeat
    false, --will the tween reverse upon finishing?
    0 --how long the delay is (in seconds)
)

local goal = { --goal for our part's property, in this case, the position
    Position = Vector3.new(69,42,0) --our goal position for our part
}

local tween = TweenService:Create(part, tweenInfo, goal) --now creates the tween

tween:Play() --finally, plays it

Here are some resources; I hope this helps! 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/enum/EasingStyle

0
Dr_Smartypants123's lerp method works too but I feel tweening is a bit easier to manipulate. wwwaylon09 113 — 3y
0
Also, how would I add orientation to this? wwwaylon09 113 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You can use https://developer.roblox.com/en-us/api-reference/class/TweenService or https://devforum.roblox.com/t/cframe-lerping-with-for-loop/1104800

0
Thanks! Works great :) wwwaylon09 113 — 3y

Answer this question