---
title: Hakoniwa-tutorial-unity
tags:  #hakoniwa  
author: [森崇](https://www.docswell.com/user/kanetugu2015)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/GJ8ND8DGED.jpg?width=480
description: この資料では、箱庭のUnityを利用する上で、Unityの基本的な使い方について情報を整理しています。 - Unityとは何か - Unityエディタの画面構成 - 基本的な操作方法 - Unityで物理シミュレーションするための基礎知識
published: April 10, 24
canonical: https://www.docswell.com/s/kanetugu2015/KJLJNV-hakoniwa-tutorial-unity
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/GJ8ND8DGED.jpg)

箱庭(Hakoniwa)
Unityの使い⽅
合同会社箱庭ラボ
森崇


# Page. 2

![Page Image](https://bcdn.docswell.com/page/LJLPMRMXER.jpg)

はじめに
• この資料では、箱庭のUnityを利⽤する上で、Unityの基本的な使い⽅につ
いて情報を整理しています。
• Unityとは何か
• Unityエディタの画⾯構成
• 基本的な操作⽅法
• Unityで物理シミュレーションするための基礎知識
• 本チュートリアル⽤のサンプルプログラムは以下で公開しています。
• https://github.com/tmori/unity-tutorial
2


# Page. 3

![Page Image](https://bcdn.docswell.com/page/47M4YRY3EW.jpg)

Unityとは何か
• ユニティ・テクノロジーズ社が開発したゲーム開発プラットフォーム
• 物理演算エンジンが搭載されています
• 質量・速度・摩擦・⾵といった，古典⼒学的な法則をシミュレーションするコンピュータのソフトウェア
• ※参照元︓ウィキペディア
• Unityでできること
• ロボット作れます
• 物理的な法則に従ってモノを動かすことができます
• ロボットの周辺環境も作れます
3


# Page. 4

![Page Image](https://bcdn.docswell.com/page/P7RW9R9RE9.jpg)

Unityエディタの画⾯構成（１／２）
Sceneビュー
Hierarchy
ビュー
Inspector
ビュー
Project
ビュー
4


# Page. 5

![Page Image](https://bcdn.docswell.com/page/PJXPQRQYEX.jpg)

Unityエディタの画⾯構成（２／２）
Gameビュー
Main Cameraを通して移した世界
Console
ビュー
ここにログが出てきます
5


# Page. 6

![Page Image](https://bcdn.docswell.com/page/3JKD9R947D.jpg)

基本的な操作⽅法
• 視点の操作
• 視点移動
• 視点回転
• ズーム操作
• ゲーム・オブジェクトの操作
• ゲーム・オブジェクト移動
• ゲーム・オブジェクト回転
• ゲーム・オブジェクト拡⼤・縮⼩
6


# Page. 7

![Page Image](https://bcdn.docswell.com/page/LE3RW8WD75.jpg)

視点移動
マウス・ホイール押しながら右左
マウス・ホイール押しながら上下
7


# Page. 8

![Page Image](https://bcdn.docswell.com/page/8EDYKMK2EG.jpg)

視点回転
右クリックしながら右左
右クリック押しながら上下
8


# Page. 9

![Page Image](https://bcdn.docswell.com/page/V7P6KRKLJ8.jpg)

ズーム操作
ズームイン
ズームアウト
9


# Page. 10

![Page Image](https://bcdn.docswell.com/page/2JV3VRV6EQ.jpg)

ゲーム・オブジェクト移動
左クリックしながら移動
10


# Page. 11

![Page Image](https://bcdn.docswell.com/page/5EG3LML27L.jpg)

ゲーム・オブジェクト回転
左クリックしながら回転
11


# Page. 12

![Page Image](https://bcdn.docswell.com/page/4JQ5YRY97P.jpg)

ゲーム・オブジェクト拡⼤・縮⼩
左クリックしながら拡⼤・縮⼩
12


# Page. 13

![Page Image](https://bcdn.docswell.com/page/K749W8ZRE1.jpg)

Inspectorビューでもできます
13


# Page. 14

![Page Image](https://bcdn.docswell.com/page/LJ1KY2RV7G.jpg)

Unityで物理シミュレーションするための基礎知識
• ゲームオブジェクト
• プリミティブな素材
• 衝突判定⽤のオブジェクト
• 物理挙動
• RigidBody
• Jointコンポーネント
• ArticulationBody
• 独⾃処理(Unityスクリプト)の追加⽅法
• Unityイベント関数の実⾏順序
14


# Page. 15

![Page Image](https://bcdn.docswell.com/page/GJWDGR1372.jpg)

ゲームオブジェクト
• Unity上のすべてのキャラやロボットはゲームオブジェクトで出来ています
• 以下のTransform情報を持ちます
• 名前
• 位置(x, y, z)
• 回転(x, y, z)
• スケール(x, y, z)
無⾊、透明です
15


# Page. 16

![Page Image](https://bcdn.docswell.com/page/4EZGLRPGJ3.jpg)

プリミティブな素材
1. Cube
2. Sphere
Cylinder
3. Capsule
4. Cylinder
5. Quad
6. Plane
Cube
Sphere
Capsule
Quad
Plane
16


# Page. 17

![Page Image](https://bcdn.docswell.com/page/Y76YWRMQEV.jpg)

衝突判定⽤のオブジェクト
• コライダの種類
• Boxコライダ
• Sphereコライダ
• Capsuleコライダ
• Meshコライダ
17


# Page. 18

![Page Image](https://bcdn.docswell.com/page/G75GM8Z274.jpg)

プリミティブな素材のコライダを⾒てみる
全オブジェクトの
Mesh Rendererをオン
全オブジェクトの
Mesh Rendererをオフ
18


# Page. 19

![Page Image](https://bcdn.docswell.com/page/9J2Y9KR1JR.jpg)

コライダによる衝突の様⼦
コライダなしの場合︓
コライダありの場合︓
19


# Page. 20

![Page Image](https://bcdn.docswell.com/page/DEYG4ND4EM.jpg)

物理挙動
• RigidBody
• Rigidbody (リジッドボディ) はオブジェクトに物理挙動を可能にするためのメインコン
ポーネントです。リジッドボディを加えた瞬間から、オブジェクトは重⼒の影響を受けるよう
になります。さらに、1つ以上の Collider (コライダー) コンポーネントを加わえれば、オブ
ジェクトは衝突の影響によって動くようになります。
20


# Page. 21

![Page Image](https://bcdn.docswell.com/page/VJNGYX6678.jpg)

Jointコンポーネント
• Joint (ジョイント) コンポーネントは、Rigidbody (リジッドボディ) を他の
Rigidbody または空間の固定点に接続します。ジョイントはリジッドボディを
動かす⼒を加え、ジョイントの制限はその動きを制限します。ジョイントはリジッ
ドボディに以下の⾃由度を与えます。
RigidBody
Joint
Jointコンポーネントの種類
RigidBody
箱庭での利⽤有無
Character Joint
×
Configurable Joint
〇
Fixed Joint
〇
Hinge Joint
〇
Spring Joint
×
21


# Page. 22

![Page Image](https://bcdn.docswell.com/page/YE9WP8LRE3.jpg)

Fixed Joint
• SphereにFixed Jointコンポーネントをアタッチし、Capsuleと接続する
Sphere
Fixed Jointを付ける
Capsule
22


# Page. 23

![Page Image](https://bcdn.docswell.com/page/GE8ND8XG7D.jpg)

Fixed Joint
23


# Page. 24

![Page Image](https://bcdn.docswell.com/page/LELPMR8X7R.jpg)

Hinge Joint
• リジッドボディを、他のリジッドボディや空間上の点に、共有された原点で
取り付け、その原点の特定の軸を中⼼に回転させることができます。ドア
や指の関節を模倣するのに便利です。
回転位置
（Anchor）
ジョイントする
RigidBody
回転対象
RigidBody
回転方向
（Axis）
24


# Page. 25

![Page Image](https://bcdn.docswell.com/page/4JM4YR637W.jpg)

Hinge Jointの例
回転位置
（Anchor）
回転方向
（Axis）
ジョイントする
RigidBody
回転対象
RigidBody
回転速度/⼒を決める
パラメータ
25


# Page. 26

![Page Image](https://bcdn.docswell.com/page/PJRW9RPR79.jpg)

Hinge Joint
26


# Page. 27

![Page Image](https://bcdn.docswell.com/page/PEXPQR3Y7X.jpg)

物理挙動
• ArticulationBody
• Articulation Body (連結ボディ) を使うことによって、ゲームオブジェクトを使ったロボッ
トアームやキネマティックチェーンのような 物理的連結 を構築することができます。これら
は、産業⽤アプリケーションのシミュレーションのコンテキストでリアルな物理動作を得るの
に役⽴ちます。
• 連結ボディは、RigidBody や 通常のジョイント といった従来の構成で定義されるプロ
パティを、1 つのコンポーネントで定義することができます。ただし、これらのプロパティは、
階層内のゲームオブジェクトの位置に依存します。
27


# Page. 28

![Page Image](https://bcdn.docswell.com/page/3EKD9RY4JD.jpg)

プロジェクト設定を変更する必要あります
28


# Page. 29

![Page Image](https://bcdn.docswell.com/page/L73RW89DJ5.jpg)

論よりRUN!
• RigidBodyをやめて、ArticulationBodyに変更する︕
Articulation Bodyをア
タッチするだけ︕︕
29


# Page. 30

![Page Image](https://bcdn.docswell.com/page/87DYKMG27G.jpg)

ArticulationBody
30


# Page. 31

![Page Image](https://bcdn.docswell.com/page/VJP6KR3LE8.jpg)

Fixed
31


# Page. 32

![Page Image](https://bcdn.docswell.com/page/2EV3VR467Q.jpg)

Hinge Jointと同じ設定したい場合
CubeをCylinder配下に移動
CylinderのArticulationBodyの接合部分および回
CylinderのArticulationBodyの接合部
転⽅向を編集
分および回転⽅向を編集
Joint Typeを Revolute にして、回転
設定する


# Page. 33

![Page Image](https://bcdn.docswell.com/page/57G3LM12JL.jpg)

Revolute
33


# Page. 34

![Page Image](https://bcdn.docswell.com/page/4EQ5YRD9JP.jpg)

独⾃処理(Unityスクリプト)の追加⽅法（１／２）
• Unityのゲームオブジェクトには、Unityスクリプト（C#）を追加できます
シミュレーション開始
時に呼び出されます
フレーム毎に呼び出さ
れます
34


# Page. 35

![Page Image](https://bcdn.docswell.com/page/KJ49W8GR71.jpg)

独⾃処理(Unityスクリプト)の追加⽅法（２／２）
35
35


# Page. 36

![Page Image](https://bcdn.docswell.com/page/LE1KY2DVJG.jpg)

Unityイベント関数の実⾏順序
• https://docs.unity3d.com/ja/2023.2/Manual/ExecutionOrder.html
Start()
FixedUpdate()
Update()
Initialization
Physics
Rendering
Input events
End of frame
Game logic
Pausing
Decommissioning
36


# Page. 37

![Page Image](https://bcdn.docswell.com/page/GEWDGRY3J2.jpg)

Unityイベント関数の実⾏順序
箱庭ロボットのセンサ/アクチュエータ
実装はFixedUpdate()内で実⾏
されます
37


# Page. 38

![Page Image](https://bcdn.docswell.com/page/47ZGLRXGE3.jpg)

Unityイベント関数の実⾏順序
38


# Page. 39

![Page Image](https://bcdn.docswell.com/page/YJ6YWR4Q7V.jpg)

Unityイベント関数の実⾏順序
39


