TweenService 完全解説(滑らかな動きを作る)
【導入】
パーツがパッと消えたり、テレポートしたりするのは味気ないよな?プロのゲームに見せるコツは「滑らかな動き」や。それを一瞬で実現するのが「TweenService」。ドアの開閉、動く床、UIのフェードインなど、使い道は無限大や。
【内容構成】
- TweenServiceとは?
- 始点と終点を繋ぐ「補間アニメーション」の仕組み。
- TweenInfoの設定(動きの質を決める)
- 時間、EasingStyle(加速・減速)、EasingDirection、リピート回数。
- プロパティの指定
- Positionだけでなく、SizeやColor、Transparencyも動かせる。
- 実行と完了待ち
:Play()とCompleted:Wait()の使い分け。
【サンプルコード(一部)】
Lua
local TweenService = game:GetService("TweenService")
local part = script.Parent
local info = TweenInfo.new(
2, -- 秒数
Enum.EasingStyle.Sine, -- 動きの種類
Enum.EasingDirection.Out, -- 方向
0, -- リピート
false -- 逆再生
)
local goal = {
Position = part.Position + Vector3.new(0, 10, 0),
Transparency = 0.5
}
local tween = TweenService:Create(part, info, goal)
tween:Play()