0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Roblox】モデルを回転させる2つの方法:PivotToとTweenService

0
Posted at

はじめに

モデルを回転させる短いサンプルコードと、設定について書きました。

🪅方法1.PivotTo()

一瞬でモデルを回転させるには、PivotTo() を使います。
Weld の必要はなく、アンカーしていてもしていなくても大丈夫です。

(例)
GetPivot() で モデルの現在の CFrame を取得します。
CFrame.Angles() で、角度(ラジアン)をもとに CFrame を作成します。
現在の CFrame に、回転の CFrame を掛けることで、現在の方向を基準に回転します。

-- ローカルX軸を中心に90度回転
local model = script.Parent
model:PivotTo(model:GetPivot() * CFrame.Angles(math.rad(90), 0, 0))

🔄回転の中心を PrimaryPart にする

モデルの PrimaryPart に設定したパーツは、モデルの回転の中心になります。
スクリーンショット 2026-03-05 231723.png

🔄回転の中心を モデルのピボットにする

PrimaryPart を設定しない場合は、モデルのピボットが回転の中心になります。
このピボットを編集して、回転の中心を調整します。
ピボット調整前:
スクリーンショット 2026-03-05 233502.png
実行すると手前に回転しました。
image.png

ピボットの調整
画面上部の「ピボット」を選択してピボットを変更できます。
X軸が縦になるように変更しました。
スクリーンショット 2026-03-05 233731.png
実行すると回転する向きが変わりました。
スクリーンショット 2026-03-05 233749.png

🪅方法2. TweenService

時間をかけて滑らかにモデルを回転させるには、TweenService を使います。
TweenService:Create() で、 PrimaryPart の CFrame を時間経過で目標の値(回転)まで変化する Tween を作成します。
Tween:Play() によって回転し始めます。

(例)

local TweenService = game:GetService("TweenService")

-- ローカルX軸を中心に、1秒間かけて90度回転
local model = script.Parent
local tweenInfo = TweenInfo.new(1) -- 1秒間かける
-- math.rad(90) は「90度」を「ラジアン」という単位に変換
local goal = {CFrame = model:GetPivot() * CFrame.Angles(math.rad(90), 0, 0)}
local tween = TweenService:Create(model.PrimaryPart, tweenInfo, goal)
tween:Play()

モデルの PrimaryPart を設定して、回転の中心にします。

スクリーンショット 2026-03-05 235437.png

Weld Constraint を PrimaryPart 以外に追加し、 各パーツと PrimaryPart の相対位置/向きを固定します。apple02 は Union(PrimaryPart)のほかにも、apple01 と Weld してもOKです。

💡ポイント:Weld(溶接)を忘れずに!
TweenService は指定したパーツ(PrimaryPart)の座標だけを動かします。他のパーツを一緒に動かすには、WeldConstraint で PrimaryPart と繋いでおく必要があります。
また、動かしたいパーツの CanCollide はそのままでも良いですが、Anchoredfalse にしておかないと、物理的に固定されて動けないので注意しましょう。

スクリーンショット 2026-03-05 235604.png
スクリーンショット 2026-03-05 235618.png

参考

公式リファレンス

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?