I know how to change the direction of an object using CFrame but how exactly would I make the transition of direction a smooth process instead of it instantly changing to the other parts CFrame position.
local RunService = game:GetService("RunService")
local Stepped = RunService.Stepped
local Time = 1 --In seconds
do
local OriginCFrame = Part1.CFrame
for i = 0, 1, Time/60 do
Part1.CFrame = OriginCFrame:Lerp(CFrame.new(OriginCFrame.Position, Part2.Position), i)
Stepped:Wait()
end
end
This will make the Part1 rotate towards Part2 smoothly in Time which is 1 second.
Tweens, they’re simple and very customisable!
Here’s a runthrough:
local TweenService = game:GetService("TweenService") --Get the service for tweening
local Info = TweenInfo.new(2, Enum.EasingStyle.Linear) --The information datatype, we'll use 2 seconds timing and Linear for a smooth tween
local PropertyTable = {
CFrame = CFrame.new(script.Parent.Connector.Front.Position, script.Parent.Waypointl[GoToName].Position)
--The property to tween is the index, the value is what to tween it to!
}
local Tween = TweenService:Create(
script.Parent.Connector.Front.CFrame, --The Instance to tween
Info, --The TweenInfo for the tween
propertyTable --The property table for the tween
)
Tween:Play() --Don't forget to Play!
Think of lerping as moving a CFrame along a line to get to the destination by a fraction. Many use this in loops to make a smooth tween effect although mathematically it’s just being moved to the next point by an increment each time. I couldn’t tell you the difference between vector and CFrame lerping but I assume it’s just the difference between a vector and a matrix.