Unity の Cinemachine の Dolly Cart の機能を使って、3D のゲームオブジェクトを作成したパス(経路)に沿ってなめらかに移動させる手順の後半です。
![Unity Cinemachine トップページの一部](https://compota-soft.work/wp1/wp-content/uploads/2023/12/Unity-Cinemachine-トップページの一部-1024x624.png)
今回、第2話では、CinemachineDollyCart コンポーネントを付加した Cube ゲームオブジェクトを、前回作成したドリーパスに沿って移動させる手順を紹介します。
前回の記事
前回、第1話では、ゲームオブジェクトを移動させるためのパスを CinemachineSmoothPath で作成する手順と、 CinemechinePath コンポーネントとの違いを紹介しました。
![Unity CinemachineSmoothPath は WayPoint を移動することで曲線のパスを変更できます.](https://compota-soft.work/wp1/wp-content/uploads/2023/12/Unity-CinemachineSmoothPath-は-WayPoint-を移動することで曲線のパスを変更できます.png)
ドリーパスに沿ってゲームオブジェクトを移動させる
前回、CinemachineSmoothPath で作成したドリーパスに沿ってゲームオブジェクトを移動させます。
例として Cube のゲームオブジェクトを作成します。
※ Hierarchy ウィンドウの余白で右クリックしてメニュー「3D Object」→「Cube」を選択します。
![Unity CinemachineSmoothPath を移動するゲームオブジェクトとして Cube を作成します.](https://compota-soft.work/wp1/wp-content/uploads/2023/12/Unity-CinemachineSmoothPath-を移動するゲームオブジェクトとして-Cube-を作成します.png)
Hierarchy ウィンドウの Cube ゲームオブジェクトを選択して、 Inspector ウィンドウの Add Component ボタンを押して検索ボックスに「Cinemachine Dolly Cart」と入力して Cinemachine Dolly Cart コンポーネントを付加します。
![Unity CinemachineSmoothPath を移動するゲームオブジェクトに Add Component で Cinemachine Dolly Cart を付加します.](https://compota-soft.work/wp1/wp-content/uploads/2023/12/Unity-CinemachineSmoothPath-を移動するゲームオブジェクトに-Add-Component-で-Cinemachine-Dolly-Cart-を付加します.png)
Cube ゲームオブジェクトに付加した Cinemachine Dolly Cart コンポーネントの Path プロパティに、前回作成した SmoothPath ゲームオブジェクト(CinemachineSmoothPath コンポーネントを持つゲームオブジェクト)を設定します。
Speed プロパティは初期値 0 では移動しないので 3 など適当な数値を設定します。
![Unity CinemachineSmoothPath を移動するゲームオブジェクトのCinemachine Dolly Cart の Path と Speed を設定します..](https://compota-soft.work/wp1/wp-content/uploads/2023/12/Unity-CinemachineSmoothPath-を移動するゲームオブジェクトのCinemachine-Dolly-Cart-の-Path-と-Speed-を設定します.png)
Path を設定すると、そのドリーパスの始点に Cube ゲームオブジェクトが移動して、向きもパスに沿った方向に変わりました。
![Unity CinemachineSmoothPath を移動するゲームオブジェクトのCinemachine Dolly Cart の Path と Speed を設定した結果..](https://compota-soft.work/wp1/wp-content/uploads/2023/12/Unity-CinemachineSmoothPath-を移動するゲームオブジェクトのCinemachine-Dolly-Cart-の-Path-と-Speed-を設定した結果.png)
Unity エディタの再生ボタンを押すと、ドリーパスにそって Cube ゲームオブジェクトが移動しました。
まとめ
今回、第2話では、無料でゲームも作れる Unity の、カメラの便利な機能をまとめた Cinemacine モジュールの Dolly Cart の機能を使って、CinemachineDollyCart コンポーネントを付加したCube ゲームオブジェクトを、前回作成したドリーパスに沿って移動させる手順を紹介しました。
参照サイト Thank You!
- Unity のリアルタイム開発プラットフォーム | 2D/3D、VR/AR エンジン
- Cinemachine
- Cinemachine について | Cinemachine | 2.6.0
- About Cinemachine | Cinemachine | 2.9.7
- ドリーパスの使用 | Cinemachine | 2.6.0
- Cinemachine Path | Cinemachine | 2.6.0
- Cinemachine Smooth Path | Cinemachine | 2.6.0
- Cinemachine Dolly Cart | Cinemachine | 2.6.0
- 【Unity】Cinemachine Dolly Cartでオブジェクトを動かそう! – SAT-BOX BLOG
記事一覧 → Compota-Soft-Press
コメント