Partの回転アニメーション

スムーズにパーツを回転させます。

  1. Workspace に Part を1つ追加します。
  2. Part に Script を追加します。
while true do
    script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0, math.rad(5), 0)
    wait()
end

math.ran(5) の「5」は回転角度です。数値を大きくすると早く回転します。

Modelの回転アニメーション

一般的には、複数のパーツを1つにまとめ、Model にすると思います。Model を回転させる場合は下記の通りになります。

  1. いくつかの Part を追加します。
  2. それらを Model にします。(すべて選択し、右クリックメニューで Group を実行)
  3. Model の Anchor をオンにします。
  4. Model 内の代表的な Part の名前を変更します。(下記の例では「primary」としました)
  5. Model に Script を追加します。
-- 事前にModelのPropertiesのPrimaryPartに設定するのもOK
script.Parent.PrimaryPart = script.Parent.primary

while true do
    script.Parent:SetPrimaryPartCFrame(script.Parent:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(5), 0))
    wait()
end

Modelの位置と回転角度を変更する

こちらはアニメーションではく、モデルの位置と回転角度を変更するプレログラムです。ModelのPrimaryPartが設定されている必要ががあります。

-- モデルの位置と回転角度を定義
local model = 対象のモデル
local newPosition = Vector3.new(x, y, z) -- 位置の設定
local newRotation = Vector3.new(xr, yr, zr) -- 回転角度の設定(一般的な角度で指定)

-- CFrameに変換
local newCFrame = CFrame.new(newPosition) * CFrame.Angles(math.rad(newRotation.X), math.rad(newRotation.Y), math.rad(newRotation.Z))

model:SetPrimaryPartCFrame(newCFrame)  -- モデルへの適応

Tweenアニメーションを使ったスムーズな回転

パーツを無限に回転させる場合は、Tweenアニメーション を使うのがベストでしょう。さらにこちらの方法を使うと、スムーズに自由な速度で回転させることができます。

local TweenService = game:GetService("TweenService")

local part = script.Parent		-- アニメーションするパーツ
local initialRotation = part.Orientation

local timePerRotation = 3	-- 3秒で1回転する

local rotationInfo = TweenInfo.new(timePerRotation,Enum.EasingStyle.Linear,	Enum.EasingDirection.Out,-1)    -- 最後のパラメータ「-1」で無限再生
local goal = { Orientation = initialRotation + Vector3.new(0, 360, 0) }	-- 「-」で時計回り
local rotateTween = TweenService:Create(part,rotationInfo,goal)
rotateTween:Play()

By schilverberch

ROBLOXでゲームを作ろう! 一緒にプログラミングを学びましょう。

3 thoughts on “パーツを回転させる”
    1. Partを作り、名前をHandleにします。そのPartの中にModelを入れます。
      ツールボックスの中にはたくさんのToolが入っています。
      「Tool」で検索すると見つかりますのでそれらを参考にするのが良いでしょう。

コメントを残す